MongoDB Geospatial Queries
Find within a Distance
https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/
The following will find all restaurants within five miles of the user:
db.restaurants.find({ location:
{ $geoWithin:
{ $centerSphere: [ [ -73.93414657, 40.82302903 ], 5 / 3963.2 ] } } })
ถ้าต้องการกำหนดค่า Calculate Distance เป็น Miles
3963.2 is radius of earth in Miles.
ถ้าต้องการกำหนดค่า Calculate Distance เป็น Km
6378.1 is radius of earth in Km.
Ref: https://stackoverflow.com/questions/41059429/query-location-with-kilometer-radius-in-mongodb