简体   繁体   中英

How to find locations between two radius from a point in mongodb and nodejs

I have a collection where I am keeping all the locations with lat and long. To find the records in 500m radius and 1000m radius is like following,

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

But, what if I have to find all the records between the two radiuses, like records between 500m and 1000m.

在此处输入图片说明

{
 loc: {
   $near: {
     $geometry: {
        type: "Point" ,
        coordinates: [ <longitude> , <latitude> ]
     },
     $maxDistance: <distance in meters>,
     $minDistance: <distance in meters>
   }
 }
}

MongoDB Manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM