mongodb geoNear vs near

前端 未结 4 2080
梦如初夏
梦如初夏 2021-02-04 09:17

It looks like mongodb offers two similar functions for geospatial queries - $near and $geoNear. According to the mongo docs

The

4条回答
  •  鱼传尺愫
    2021-02-04 09:32

    These are major differences :-

    1. $geoNear also gives you distance from the point but $near command doesn't.

    2. $geoNear command requires that the collection have at most only one 2d index and/or only one 2dsphere index whereas geospatial query operators like $near and $geoWithin permit collections to have multiple geospatial indexes. This is because in $geoNear command there is no option to specify the field on which you want to search, where as in $near command you can specify the field name.

提交回复
热议问题