我想在集合中找到所有具有與數組中的某個字符串相同的鍵的文檔。MongoDB找到哪裏的鍵等於從數組中的字符串
繼承人一個集合的例子。
{
roomId = 'room1',
name = 'first'
},
{
roomId = 'room2',
name = 'second'
},
{
roomId = 'room3',
name = 'third'
}
而繼承人是數組要查看的示例。
[ 'room2', 'room3' ]
什麼,我想會的工作是...
collection.find({ roomId : { $in : [ 'room2', 'room3' ]}}, function(e, r)
{
// r should return the second and third room
});
我怎樣才能做到這一點?這可以解決
一個辦法是爲循環做...
var roomIds = [ 'room2', 'room3' ];
for (var i=0; i < roomIds.length; i++)
{
collection.find({ id : roomIds[ i ]})
}
但這並不理想....
這些獨立文檔還是嵌入某些「酒店」文檔?你究竟得到什麼結果? –
您看到的3個文檔是集合中的根文檔。 – cnotethegr8