Created
February 18, 2020 01:29
-
-
Save deltastateonline/dfa6b994127999920a5a857b070b54d1 to your computer and use it in GitHub Desktop.
Using aggregate in mongoose 4.x with Mongodb 3.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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