Last active
March 23, 2016 07:02
-
-
Save rihenperry/bc105eb6fbbc3ef40b08 to your computer and use it in GitHub Desktop.
mongoose/mongoDB/NodeJS multiple doc populate 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
var notifyconfigs = [ | |
{path: 'notify_options_fk_key.buy_opt_container', model: 'BuyKeywordsOption'}, | |
{path: 'notify_options_fk_key.ask_opt_container', model: 'AskKeywordsOption'}, | |
{path: 'notify_options_fk_key.bid_opt_container', model: 'BidKeywordsOption'} | |
]; | |
if(req.params && req.params.id) { | |
Usr | |
.findById(req.params.id) | |
.populate('notify_options_fk_key') | |
.exec(function(err, user){ | |
if (!user) { | |
helpers.sendJsonResponse(res, 404, { | |
"message": "id not found" | |
}); | |
return; | |
} else if (err) { | |
helpers.sendJsonResponse(res, 404, err); | |
return; | |
} | |
Usr | |
.populate(user, notifyconfigs, function(err, result){ | |
if (err) return helpers.sendJsonResponse(res, 404, err); | |
helpers.sendJsonResponse(res, 200, result); | |
}); | |
}); | |
} else { | |
helpers.sendJsonResponse(res, 404, { | |
"message": "No id in request" | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment