我有一个mongoDB集合中的国家。国家/地区文件的示例如下:
{
"_id": 1,
"cities": [
{
"_id": ObbjectId("..."),
"neighborhoods": [
{
"_id": ObbjectId("..."),
"schools": 5,
"stadiums": [
{
"_id": ObbjectId("...")
},
{
"_id": ObbjectId("...")
}
]
},
{
"_id": ObbjectId("..."),
"schools": 3,
"stadiums": []
}
]
},
{
"_id": ObbjectId("..."),
"neighborhoods": [
{
"_id": ObbjectId("..."),
"schools": 1,
"stadiums": []
},
{
"_id": ObbjectId("..."),
"schools": 5,
"stadiums": [
{
"_id": ObbjectId("...")
},
{
"_id": ObbjectId("...")
}
]
}
]
}
]
}
要查询的是拥有至少一个拥有至少1个社区的城市且体育场馆集合为空且学校等于1的国家/地区?
谢谢!
答案 0 :(得分:1)
您可以将documentation链接在一起以构建查询。
类似
db.col.find({cities:{$elemMatch:{neighborhoods:{$elemMatch:{schools:1,stadiums:[]}}}}})