mongodb - perform batch query

后端 未结 2 846
孤街浪徒
孤街浪徒 2021-02-13 20:46

I need query data from collection a first, then according to those data, query from collection b. Such as:

For each id queried from a
    query data from b where         


        
2条回答
  •  [愿得一人]
    2021-02-13 21:17

    You'll need to do it as two steps.

    Look into the $in operator (reference) which allows passing an array of _ids for example. Many would suggest you do those in batches of, say, 1000 _ids.

    db.myCollection.find({ _id : { $in : [ 1, 2, 3, 4] }})
    

提交回复
热议问题