How is $maxDistance measured in MongoDB?

你说的曾经没有我的故事 提交于 2019-12-03 05:13:54

问题


I can't seem to find this information. But using a geo search you can specify $maxDistance but for the life of me, I can't find if that is miles, kilometers, etc.

Here is a sample query I'm using:

db.hotels.find( { location: { $near : [18.74255, 99.03523], $maxDistance : 0.05 } } ).count()

Returns 15 (from my hotels database).

Thanks for any information.


回答1:


Unless you're doing a spherical query (like $nearSphere), MongoDB doesn't actually care about units, it just treats your locations as Cartesian coordinates.

So, the calculated distance is going to be in whatever your input units were. Since your $near point looks like standard lat/long, the $maxDistance in this case will be in units of degrees.




回答2:


If you are using $near,

$maxDistance = your distance in Kms / 111 

and if you use $nearSphere,

$maxDistance = your distance in kms/ 6378

where 6378 is the earths radius in kms



来源:https://stackoverflow.com/questions/5319988/how-is-maxdistance-measured-in-mongodb

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