I have a collection called restaurants.. and also i have formatted into geoJSON and I tried to query the following way
db.restaurants.find({ location:
{ $geoWithin:
{ $centerSphere: [ [ -73.93414657, 40.82302903 ], 5 / 3963.2 ] } } })
I have mentioned radius 5/3963.2 (calculation in miles).. but I need radius distance in kilometer like { $centerSphere: [ [ -73.93414657, 40.82302903 ], 5] }
I need to mentioned radius in kilometer
How to do it?
MongoDB expects values in radians.
To convert distance to radians, simply divide the distance value to the radius of the sphere (earth), where:
3963.2 is radius of earth in Miles.
6378.1 is radius of earth in Km.
db.restaurants.find({ location:
{ $geoWithin:
{ $centerSphere: [ [ -73.93414657, 40.82302903 ], 5 / 6378.1 ] } } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With