开发者

Can you nest collection calls? MongoDB

开发者 https://www.devze.com 2023-04-09 02:46 出处:网络
Can you nest collection calls in MongoDB? db.collection \'one\', (err, on开发者_如何转开发e) ->

Can you nest collection calls in MongoDB?

db.collection 'one', (err, on开发者_如何转开发e) ->
    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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号