In other words, how can I chain MongoDB .find()
s so that the second .find()
searches the cursor returned by the first .find()
?
MySQL has subquery support.
In other words, how can I chain MongoDB .find()
s so that the second .find()
searches the cursor returned by the first .find()
?
MySQL has subquery support.
Subqueries and joins are a very 'relational' thing, so you might want to reconsider your design. In any case, you can't join collections directly, but you can use $in
, e.g.:
> foo = [];
[ ]
> db.Comment.find().forEach(function(rover) {foo.push(rover.UserId)})
> foo
[
ObjectId("535fd8e6eb596a27ec924d15"),
ObjectId("536a6479eb596a2a283f43e8"),
ObjectId("536a5fa4eb596a2a283f43de")
]
> db.User.find({"_id" : {$in : foo}});
{ "_id" : ObjectId("535fd8e6eb596a27ec924d15"), "FirstName" : "John", ...