我的MongoDB中有以下文档结构:
[{
"_id": "59afce079af65f48de8fb609",
"some_fields": "...",
"members": [
{
"some_fields": "...",
"device_id": "7FD45D19-F746-4293-A410-60B485E617F2",
"_id": "59afce079af65f48de8fb60a"
},
{
"some_fields": "...",
"device_id": "7AC1635B-3E39-4F43-A4D4-4927FA072F89",
"_id": "59afd01cff27894e8237eb2d"
}
]
}]
如何使用Mongoose查找documents which members contain object where device_id == "given_id"
?
答案 0 :(得分:0)
尝试这个:
使用elemMatch:
db.collection.find({members: {$elemMatch: {device_id:'your ID'}}})