mongodb geoNear vs near

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

    Efficiency should be identical for either.

    geoNear's major limitation is that as a command it can return a result set up to the maximum document size as all of the matched documents are returned in a single result document. It also requires that a distance field be added to each result document which may or may not be an issue depending on your usage.

    $near is a query operator so the results can be larger than a single document (they are still returned in a single response but not a single document). You can also set the maximum number of documents via the query's limit().

    I tend to recommend that users stick with the $near unless they need the diagnostics (e.g., distance, or location matched) from the geonear command.

提交回复
热议问题