Reputation: 4171
Suppose you have a list of id-s which can contain up to thousands id-s for the documents inside the database. What is the best way to get those documents back?
Should I invoke a query for each of them or should I specify a giant OR query? may be there is something way better I do not know of
Upvotes: 6
Views: 3330
Reputation: 53705
In c# code, $in:
var ids = new int[] {1, 2, 3, 4, 5};
var query = Query.In("name", BsonArray.Create(ids));
var items = collection.Find(query);
Upvotes: 8
Reputation: 18625
There is, $in :
db.co.find({_id:{$in:[id1, id2, id3, .., idN]}})
Upvotes: 7