Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query the MongoDB for the documents whose id-s are contained inside a list

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

like image 674
Yurii Hohan Avatar asked Oct 25 '11 08:10

Yurii Hohan


1 Answers

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);
like image 102
Andrew Orsich Avatar answered Sep 20 '22 00:09

Andrew Orsich