Can you nest collection calls in MongoDB?
db.collection 'one', (err, one) ->
one.#do stuff
db.collection 'two', (err, two) ->
two.#do stuff
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes.
This is (as far as I am aware) the simplest way of doing things in MongoDB and Node.js.
In your example
onewill contain the results of the first query, andtwothe results of the second.If you are doing a lot of nested queries, where the nested query does not depend on the results of the outer query, you could consider using the Async module (or an alternative) to parallelise the query.