How to traverse query in mongodb?
天蓬老师
天蓬老师 2017-06-27 09:18:17
0
1
1215

There is an existing array as follows,

const idArr = ['5950b7bfe78afb0868dc6599','5950b532b3c06f0838ed47e2','5950afcc85881f07bf454232'];
//数组每一项都作为查询的_id,遍历查询,该如何操作呢?

idArr.forEach((item,index)=>{
    db.details.find({_id:item}); //这样吗?还是。。。
});
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
黄舟

The answer was found in the official documentation of mongodb

const idArr = ['5950b7bfe78afb0868dc6599','5950b532b3c06f0838ed47e2','5950afcc85881f07bf454232'];
db.details.find({_id:{$in:idArr}); //这样就可以了,一次全部查出来
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!