【问题标题】:MongoDB - Geospatial distance problemMongoDB - 地理空间距离问题
【发布时间】:2011-09-21 09:30:35
【问题描述】:

我在属性“位置”上有一个二维地理空间索引。我正在尝试查询纬度/经度位置给定范围内的某些实体。如果我使用 geoNear 命令,我会得到正确的结果:

distances = db.runCommand({ geoNear: "Places", near: [40.423776,-3.711534], spherical: true, maxDistance: 10/6378}).results

In 输出给定坐标 10 公里内的所有地点。

但如果我执行以下查询,我不会得到任何结果:db.Places.find({location: { $near [40.423776,-3.711534], $maxDistance: 10/6378, $nearSphere: true }})

我做错了吗?

【问题讨论】:

    标签: mongodb geolocation


    【解决方案1】:

    $nearSphere 应该这样使用

    db.Places.find({location:{$nearSphere:[[40.423776,-3.711534],10/6378]}}).count()
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-09
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      相关资源
      最近更新 更多