本文介绍了Mongo:如何通过存储在子数组中的ObjectId查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的记录集合:
I have a collection with records like this:
{
"_id" : ObjectId("50ae3bdb50b3d6f01400027a"),
"admins":
[ObjectId("50ae3bdb50b3d6f014000279"), ObjectId("50ae3bdb50b3d6f01400027e")]
}
我想通过'admin'数组进行搜索.
I would like to search by the the 'admin' array.
如何在子数组中找到所有包含的文档,例如ObjectId("50ae3bdb50b3d6f014000279").
How can I find all documents included for example ObjectId("50ae3bdb50b3d6f014000279") in the sub-array.
谢谢.
推荐答案
您可以像对非数组字段一样对admins
这样的数组字段进行匹配:
You can match against array fields like admins
the same as you would a non-array field:
db.coll.find({admins: ObjectId("50ae3bdb50b3d6f014000279")})
这篇关于Mongo:如何通过存储在子数组中的ObjectId查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!