MongoDB 选择_id 数组中的位置? [英] MongoDB select where in array of _id?
本文介绍了MongoDB 选择_id 数组中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以在 mongo db 中像在 SQL 中一样选择集合的文档:
is possible in mongo db to select collection's documents like in SQL :
SELECT * FROM collection WHERE _id IN (1,2,3,4);
或者如果我有一个_id数组
,我必须一一选择,然后重新组合结果的array/object
?
or if i have a _id array
i must select one by one and then recompose the array/object
of results?
推荐答案
简单 :)
db.collection.find( { _id : { $in : [1,2,3,4] } } );
取自:http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24in
这篇关于MongoDB 选择_id 数组中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文