Py学习  »  MongoDB

如何在MongoDB和Nodejs中找到两个半径之间的位置

NitinD • 4 年前 • 203 次点击  

我有一个藏品,我把所有的地点都放在那里。 在500米半径和1000米半径范围内查找记录如下:

{
  loc: {
    $geoWithin: {
      $centerSphere: [[lng, lat], (radiusInMiles / 3963.2)]
    }
  }
}

但是,如果我必须找到两个半径之间的所有记录,比如500米到1000米之间的记录,该怎么办?

enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38176
 
203 次点击  
文章 [ 1 ]  |  最新文章 4 年前
wajih
Reply   •   1 楼
wajih    5 年前
{
 loc: {
   $near: {
     $geometry: {
        type: "Point" ,
        coordinates: [ <longitude> , <latitude> ]
     },
     $maxDistance: <distance in meters>,
     $minDistance: <distance in meters>
   }
 }
}

MongoDB Manual