Last active
December 17, 2015 00:38
-
-
Save johnschimmel/5522134 to your computer and use it in GitHub Desktop.
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 friendQuery = models.User.findById(userID); | |
friendQuery.exec(function(err, currentUser){ | |
// filter Users by _id using .friends id array | |
// $in operator in Mongo allows you to use an array as search param | |
// http://docs.mongodb.org/manual/reference/operator/#AdvancedQueries-%24in | |
// in mongoose http://mongoosejs.com/docs/api.html#query_Query-in | |
var filter = { _id : { $in : currentUser.friends } }; | |
// select the fields you want | |
var fields = 'name photo'; | |
// build and run the query, | |
// you'll get an array of the objects with the fields | |
// or you'll get an error. | |
var query = models.User.find(filter, fields); | |
query.exec(function(err, friendData){ | |
res.json(friendData); // return json | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment