我在mongo shell中使用此查询来获取仅与Person1相关的信息
db.collection.find({ "member.name": "Person1" }, { member: { $elemMatch: { name: "Person" } }, number: 1 })
我怎么用python编写?这是我尝试过的,但是会输出所有内容:
collection.find(dict(member = { "$elemMatch": dict(name = "Person1") }))
我的数据库:
{
"number": 0,
"member": [{
"name": "Person1",
"ad": {
"firstline": 123,
"secondline": 456
}
}, {
"name": "Person2",
"ad": {
"firstline": 345,
"secondline": 1256
}
}]
}
{
"number": 1,
"member": [{
"name": "Person1",
"ad": {
"firstline": 1323,
"secondline": 4536
}
}, {
"name": "Person2",
"ad": {
"firstline": 3245,
"secondline": 123456
}
}]