Last active
September 18, 2017 14:39
-
-
Save nicholasess/84d96e8525fa7592c0f3d232bc4f9fac to your computer and use it in GitHub Desktop.
query
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
palpites.find({user_id:'1234'}).limit(5).ski(page * 5).exec(function(err, results) { | |
results = results.map(function(palpite){ | |
var confrontos = palpite.confrontos.map((item){ return item.confronto_id }) | |
return new Promise(function(resolve){ | |
confronto.find({_id: {$in: confrontos} }).exec(function(err, confrontos){ | |
palpite.confrontos = confrontos; | |
resolve(palpite) | |
}) | |
}) | |
}) | |
Promise.all(results).then(function(results){ | |
//todos os palpites com confrontos populados | |
return res.status(200).json(results) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment