【问题标题】:Mongodb : How to find out all the documents which are near certain location?Mongodb:如何找出某个位置附近的所有文件?
【发布时间】:2016-01-19 15:13:52
【问题描述】:

我在 mongodb 中收集了 shops 具有以下重要属性

{  
  .......  
  address:{  
    ....  
    lat:15.9844,  
    lon:18:3333  
   }  
}

我还有一个person 收藏,其中包含他的纬度和经度信息。 我想找出那个人附近的所有商店(比如商店和人之间的距离小于 500 米)。

我正在尝试使用 nodejs 编写和查询。我写了一个函数,它需要两个位置并找出它们之间的距离。我该如何编写查询? 提前感谢您的帮助:)

【问题讨论】:

    标签: javascript node.js mongodb geolocation


    【解决方案1】:

    将 lat 和 lon 更改为坐标:[15.9844,18:3333]

    db.shops.find(
           {
             address:
               { $near :
                  {
                    $geometry: { type: "Point",  coordinates: [ <longitude> , <latitude> ] },
                    $minDistance: 0,
                    $maxDistance: 500
                  }
               }
           }
        )
    

    【讨论】:

      猜你喜欢
      • 2019-10-30
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多