在Python中使用PyMongo,我试图在一个设置的半径内对源LatLon和目的LatLon执行地理空间查询,并打印第一个结果。下面是我想的,但是我得到了一个错误。正确的做法是什么?在
代码:
origin = [float(44.8697193), float(13.8414046)]
dest = [float(48.1367203), float(11.576754)]
query = db.collection.find({'origLatLng': {'$within': {'$center': [origin,.75]}}}, {'destLatLng': {'$within': {'$center': [dest,.75]}}})[0]
print query
错误:
^{pr2}$不要在没有目标的情况下搜索目标。我做错什么了?在
不确定您正在使用的实际MongoDB版本,但是
$within
已被弃用,现在您应该使用$geoWithin
:http://docs.mongodb.org/manual/reference/operator/geoWithin/
另请参阅上面的链接了解更多选项。我不是Python的专家,但我希望
$geoWithin
能解决您的问题。在我觉得你的语法有问题。实际上有两个查询文档,一个用于
origLatLng
,另一个用于destLatLng
。我想你的意思是:您的第二个查询文档被解释为执行一个投影,这就是为什么使用“Unsupported projection option:
$within
”的操作失败的原因。在相关问题 更多 >
编程相关推荐