如何按顺序查询ID批量文档

时间:2016-08-23 05:21:38

标签: mongodb mongodb-query

如何按ids查询一批文件(其中的元素可能重复),例如

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"},]

查询结果应与ids的顺序相同,结果中可能存在重复的对象。

Mongodb可以吗?

0 个答案:

没有答案