我有这个简单的数据库,其中包含元素子集:
{ "_id" : ObjectId("5019eb2356d80cd005000000"),
"photo" : "/pub/photos/file1.jpg",
"comments" : [
{
"name" : "mike",
"message" : "hello to all"
},
{
"name" : "pedro",
"message" : "hola a todos"
}
]
},
{ "_id" : ObjectId("5019eb4756d80cd005000001"),
"photo" : "/pub/photos/file2.jpg",
"comments" : [
{
"name" : "luca",
"message" : "ciao a tutti"
},
{
"name" : "stef",
"message" : "todos bien"
},
{
"name" : "joice",
"message" : "vamos a las playa"
}
]
}
当我执行子集查找时: db.photos.find({},{"comments.name":1})
我收到这个结构:
[
{
"_id" : ObjectId("5019eb2356d80cd005000000"),
"comments" : [
{
"name" : "mike"
},
{
"name" : "pedro"
}
]
},
{
"_id" : ObjectId("5019eb4756d80cd005000001"),
"comments" : [
{
"name" : "luca"
},
{
"name" : "stef"
},
{
"name" : "joice"
}
]
}
]
但我想得到一个简单的一维数组,像这样(或类似的):
[
{
"name" : "mike"
},
{
"name" : "pedro"
},
{
"name" : "luca"
},
{
"name" : "stef"
},
{
"name" : "joice"
}
]
我需要用mongo php官方驱动来实现这个查询,但是语言并不重要,我只是想了解通过mongo shell可以通过什么逻辑来完成这个
天呐!