mongodb 中的嵌套查询
nested query in mongodb
如何查询 mongoDB 2 或 3 中以下文档中的所有标签:
{
"_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" : ""
}
]
}
我需要这样的结果:
{['aa','bb','cc'], ['da','db','dc']}
我需要 doctrine odm 中的查询样式。
尝试这样的事情:
db.collection.find({}, {"allNews.tag" : 1, _id : 0})
如何查询 mongoDB 2 或 3 中以下文档中的所有标签:
{
"_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" : ""
}
]
}
我需要这样的结果:
{['aa','bb','cc'], ['da','db','dc']}
我需要 doctrine odm 中的查询样式。
尝试这样的事情:
db.collection.find({}, {"allNews.tag" : 1, _id : 0})