我还有一个基于此question,
的问题{
"family": "Smith",
"children": [
{
"child_name": "John",
"age":5
},
{
"child_name": "Anna",
"age":6
},
]
}
{
"family": "Williams",
"children": [
{
"child_name": "Anna",
"age":6
},
{
"child_name": "Kevin",
"age":7
},
]
}
作为最高投票答案显示,我可以通过以下代码获得不同的子名称,
db.collection.distinct("children.child_name");
我的问题是如何获取每个不同子名称的整个子文档?
这意味着我希望根据唯一子名称
返回子文档列表[ {"child_name":"John", "age":5}, {"child_name": "Anna","age":6}, {"child_name":"Kevin","age":7}]