私は要素のサブセットを持つこの単純なデータベースを持っています:
{ "_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"
}
]
}
]
しかし、次のような(または同様の)単純な1次元配列を取得したい:
[
{
"name" : "mike"
},
{
"name" : "pedro"
},
{
"name" : "luca"
},
{
"name" : "stef"
},
{
"name" : "joice"
}
]
このクエリをmongo php公式ドライバーで実装する必要がありますが、言語は重要ではありません。mongoシェルでこれを達成できるロジックを理解したいだけです
tnk!