mongodb geoNear vs near

前端 未结 4 2081
梦如初夏
梦如初夏 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:22

    The main difference is that $near is a query operator, but $geoNear is an aggregation stage. Both return documents in order of nearest to farthest from the given point.

    What it means is that $near can be used in find() queries or in the $match aggregation stage, but $geoNear cannot. Instead $geoNear must be used as a separate aggregation stage only.

    The options each feature provides also differ. I invite you to review the details in the corresponding documentaiton sections:

    $near documentation
    $geoNear documentation

提交回复
热议问题