[英]Nested document query mongodb (dot notation not working)
我在共享-> 内容--> 创建者中有一个嵌套文档。 目前我有一个 creatorId (创建者对象的_id),我正在尝试查找所有共享的内容映射到创建者。
但无论我如何尝试(对于点符号),它似乎都不起作用。 这是我尝试过的(其中 creatorId 是嵌套文档的 id 的字符串:
let shares = await Share.find({"content.creator": ObjectId(creatorId)})
let shares = await Share.find({"content.creator": creatorId)})
let shares = await Share.find({"content.creator._id": creatorId})
我究竟做错了什么? 谢谢!
Share: { _id: 5f1690a8d15ff6558cb48cc1,
__v: 0,
content:
{ _id: 5f1690a7d15ff6558cb48cc0,
creator:
{ _id: 5f166ce0c6b1744fee6b28e7,},
__v: 0,
}
}
Please find use objectId type
db.collection.find({
"content.creator._id": ObjectId("5f166ce0c6b1744fee6b28e7")
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.