【发布时间】:2017-09-29 22:05:46
【问题描述】:
我有以下 pymongo 查询来从 MongoDB(3.0) 中检索 geoNear 数据。 “距离”以公里为单位传递,我从 MongoDB 文档中了解到“最大距离”必须以米为单位,因此我在查询中使用“距离 * 1000”
def getNearestVoices(self, longitude, latitude, distance, userid=None, count='500'):
response = []
for doc in self.users.aggregate([{"$geoNear": {"near": [longitude, latitude],
"distanceField":"distance",
"maxDistance": (distance * 1000),
"distanceMultiplier": 6371,
"num": int(count),
"spherical": True}}]):
pass
现在,当我为距离传递“1”时,我的期望是返回匹配 1 公里或更短的“距离”,但这并没有发生,并且所有记录都被返回。
我还注意到一件事,当我在 mongo 查询中将“距离 * 1000”更改为“距离 / 1000”时,我得到的记录较少,但仍然不符合我的预期。
我无法弄清楚我的查询出了什么问题。
PS:我正在使用 distanceMultiplier 6371 来检索以公里为单位的输出
谢谢
【问题讨论】:
标签: mongodb geolocation pymongo