如何在mongoDB 2或3中查询以下文档中的所有标记:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 14.069489,
"hits": [
{
"_index": "reviewer-bdd-test-index",
"_type": "importFile",
"_id": "AU9kUka2hr5Jg98UXOae",
"_score": 14.069489,
"_source": {
"fileName": "Group-1.uhh",
"groupId": "0ae1206d0644eabd82ae490e612732df5da2cd141fdee70dc64207f86c96094f",
"filePath": ""
}
},
{
"_index": "reviewer-bdd-test-index",
"_type": "importFile",
"_id": "AU9kZO25hr5Jg98UXRnk",
"_score": 14.069489,
"_source": {
"fileName": "group-1.uhh",
"groupId": "0ae1206d0644eabd82ae490e612732df5da2cd141fdee70dc64207f86c96094f",
"filePath": ""
}
}
]
}
}
我在结果中需要这样的东西:
{
"_id" : ObjectId("55dc45017137a4e70b8b4569"),
"campainName" : "",
"themeName" : "theme1",
"emailListName" : "eiEmails",
"emailSubject" : "",
"emailFrom" : "",
"allNews" : [
{
"type" : "1",
"tag" : ['aa','bb','cc'],
"link" : "",
"image" : ""
}
]
},
{
"_id" : ObjectId("55dc45017137a4e70b8b4570"),
"campainName" : "",
"themeName" : "theme2",
"emailListName" : "afaeiEmails",
"emailSubject" : "",
"emailFrom" : "",
"allNews" : [
{
"type" : "1",
"tag" : ['da','db','dc'],
"link" : "",
"image" : ""
}
]
}
我需要在教条中使用查询风格。
答案 0 :(得分:1)
尝试这样的事情:
db.collection.find({}, {"allNews.tag" : 1, _id : 0})