MongoDB Bound Queries: How do I convert mile to radian?

好久不见. 提交于 2019-12-02 20:44:44

As docs say:

All distances use radians. This allows you to easily multiply by the radius of the earth (about 6371 km or 3959 miles) to get the distance in your choice of units. Conversely, divide by the radius of the earth when doing queries.

so you simple need to divide your radius by the earth radius. in your example it would be:

radius = 10/3959

In order to use mongodb $near queries with km bounds, you need to convert the radius value to km. By default mongodb $near accepts $maxDistance as radius.

Convert distance by 111.12 (one degree is approximately 111.12 kilometers) when using km, or leave distance as it is on using degree

let if your radius is in km then use

 db.places.find( { loc : { $near : [50,50] , $maxDistance : 10/111.12 } } )

but if your radius in miles then convert it in km

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!