Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deltastateonline/dfa6b994127999920a5a857b070b54d1 to your computer and use it in GitHub Desktop.
Save deltastateonline/dfa6b994127999920a5a857b070b54d1 to your computer and use it in GitHub Desktop.
Using aggregate in mongoose 4.x with Mongodb 3.6
return new Promise((resolve, reject) => {
var allResultsCursor = this.model('Combined').aggregate([{
// $match object
// $lookup
// $unwind
// $group
// $project
]).cursor({ batchSize: 1000 })
.exec();
var resultPayload = [];
allResultsCursor.eachAsync(result => { // loop thru and colllect result
resultPayload.push(result);
})
.then(() => {
resolve(resultPayload) ; // resolve with the final payload
})
.catch(err => reject(err));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment