1

How to query a batch of documents by ids (the elements of it might be duplicate), for example

var ids = [
  "57470bda627fe714555d96d1", "57470bda627fe714555d2401",             
  "57470bda627fe714555d9922" , "57470bda627fe714555d2401",
  "57470bda627fe714555d2401"
];

var results = db.collection('Person').find(query_containing_ids);

//The desired results
results = [{_id:"57470bda627fe714555d96d1", name:"xxxx"},
           {_id:"57470bda627fe714555d2401", name:"yyy"},
           {_id:"57470bda627fe714555d96d1", name:"xxxx"},
           {_id:"57470bda627fe714555d2401", name:"yyyy"},
           {_id:"57470bda627fe714555d2401", name:"yyyy"},]

The query results should be in the same order as ids and there might be duplicate objects in the results.

Is it that possible in Mongodb?

ppn029012
  • 580
  • 1
  • 6
  • 20

0 Answers0