我有一个类似下面的集合
{
"_id" : ObjectId("573eb77bf3465096ddb1e873"),
"id" : 1,
"name" : "siva",
"email" : "sivateja@gmail.com",
"address" : [
{ "street" : "balajinager", "district" : "nellore", "state" : "A.p" },
[ { "street" : "balajinager", "district" : "nellore", "state" : "A.p" } ]
]
}
我想根据city
数组内的address
来过滤记录,我们怎么能在mongo db中做到这一点?
答案 0 :(得分:0)
地区还好吗?
{address:{$elemMatch:{district:"nellore"}}}
请参阅https://docs.mongodb.com/manual/reference/operator/query/elemMatch/