【问题标题】:List locations near by to a lat, lon point from stored lat, lon in database列出数据库中存储的 lat, lon 到 lat, lon 点附近的位置
【发布时间】:2018-12-04 14:46:09
【问题描述】:

我有 [lat, lon] 对存储在 MongoDb 中的不同位置。现在我想按距离比较某个坐标对,例如距离该点 2 公里 的圆圈,并希望从数据库中获取所有结果。

【问题讨论】:

    标签: node.js mongodb google-maps gis geojson


    【解决方案1】:

    你应该看看geoNear 命令。

    通用示例如下:

    db.runCommand(
       {
         geoNear: "places", // Your target collection
         near: { type: "Point", coordinates: [ -73.9667, 40.78 ] }, // Point coordinates
         spherical: true, // 2dsphere index required for using this option
         query: { yourField: "someFilterVale" }, // Additional regular filtering
         maxDistance: 2000 // Maximum distance in meters/radians
       }
    )
    

    minDistance也可以查询

    为此,您的收藏中应该有 2d2dsphere 索引。

    还有一个$geoNear 聚合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多