gpt4 book ai didi

arrays - 蒙哥 : how to find by ObjectId that is stored in a subarray?

转载 作者:IT老高 更新时间:2023-10-28 13:19:56 28 4
gpt4 key购买 nike

我有一个包含这样记录的集合:

{
"_id" : ObjectId("50ae3bdb50b3d6f01400027a"),
"admins":
[ObjectId("50ae3bdb50b3d6f014000279"), ObjectId("50ae3bdb50b3d6f01400027e")]
}

我想通过 'admin' 数组进行搜索。

如何找到子数组中包含的所有文档,例如 ObjectId("50ae3bdb50b3d6f014000279")。

谢谢。

最佳答案

您可以像匹配非数组字段一样匹配 admins 等数组字段:

db.coll.find({admins: ObjectId("50ae3bdb50b3d6f014000279")})

关于arrays - 蒙哥 : how to find by ObjectId that is stored in a subarray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13515728/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com