在我的 Mongo 中有以下文档,我试图获取具有指定 ID 的对象。这是我的 Mongo 文档。蒙哥版本:2.6
{
"_id" : ObjectId("57c1ae9ac1bd31d4eb4d546d"),
"footers" : [
{
"type" : "web",
"rows" : [
{
"id" : "abc",
"elements" : [
{
"id" : "def",
"type" : "image",
"url" : "http://example.com"
},
{
"id" : "ghi",
"type" : "image",
"url" : "http://example.com"
}
]
}
]
}
]
}
我正在寻找一个 id 为“def”的对象,我想获得这个结果:
{
"id" : "def",
"type" : "image",
"url" : "http://example.com"
}
下面我引用了我试图搜索这个对象的代码示例。
db.getCollection('myCollection').aggregate([
{"$match": {
"footers.rows.elements.id": "def"
}},
{"$group": {
"_id": "$footers.rows.elements"
}}
])
结果是:
{
"_id" : [
[
[
{
"id" : "def",
"type" : "image",
"url" : "http://example.com"
},
{
"id" : "ghi",
"type" : "image",
"url" : "http://example.com"
}
]
]
]
}
有什么建议么?