【问题标题】:PyMongo - MaxDistance operation working but results are not as expectedPyMongo - MaxDistance 操作正常,但结果不如预期
【发布时间】: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


    【解决方案1】:

    变化

    "maxDistance": (distance * 1000)"
    

    "maxDistance": (distance / 6371)
    

    为我工作。由于我使用的是距离乘数,我认为我必须将其考虑在内

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多