简体   繁体   中英

Can you nest collection calls? MongoDB

Can you nest collection calls in MongoDB?

db.collection 'one', (err, one) ->
    one.#do stuff
    db.collection 'two', (err, two) ->
        two.#do stuff

Yes.

This is (as far as I am aware) the simplest way of doing things in MongoDB and Node.js.

In your example one will contain the results of the first query, and two the 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM