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

前端 未结 2 1206
无人共我
无人共我 2021-02-02 14:18

I have a collection of stores with a geospacial index on the location propery.

What I am trying to do is given the user\'s latitude, latitude and a search radius (mi), I

2条回答
  •  隐瞒了意图╮
    2021-02-02 14:56

    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

提交回复
热议问题