Python $lte和$gte不起作用的Pymongo查询
我在mongo有以下文件:Python $lte和$gte不起作用的Pymongo查询,python,mongodb,pymongo,database,Python,Mongodb,Pymongo,Database,我在mongo有以下文件: { 'Name': 'Dummy', 'North-East-Bound': { 'lat': 0, 'lng': 0 }, 'South-West-Bound': { 'lat': 0, 'lng': 0 } } 我正在执行以下查询: result = self.coll.find_one({ 'North-East-Bound':
{
'Name': 'Dummy',
'North-East-Bound': {
'lat': 0,
'lng': 0
},
'South-West-Bound': {
'lat': 0,
'lng': 0
}
}
我正在执行以下查询:
result = self.coll.find_one({
'North-East-Bound':
{'lat': {'$gte': lat},
'lng': {'$gte': lng}
},
'South-West-Bound':
{'lat': {'$lte': lat},
'lng': {'$lte': lng}
}
})
显然,我使用lat=0和lng=0作为参数。我希望返回虚拟文档,但我一个也没有得到。我做错了什么
谢谢。您必须使用点表示法在字段上运行嵌入文档的查询
find_one({
'North-East-Bound.lat': {
'$gte': lat
},
'North-East-Bound.lng': {
'$gte': lng
},
'South-West-Bound.lat': {
'$lte': lat
},
'South-West-Bound.lng': {
'$lte': lng
}
})
这将有助于平等比较。这是嵌入式文档级比较
find_one({
'North-East-Bound': {
'lat': 0,
'lng': 0
},
'South-West-Bound': {
'lat': 0,
'lng': 0
}
})
更多