Search code examples
mongodbgeolocationaggregation-framework

mongo DB geoNear aggregation framework


I wonder if the geoNear query is similar to the geoNear operator in the new aggregation framework? (performance aspect)

and if not what is the difference and which is better..

Thanks.


Solution

  • The geoNear query uses a cursor and iterates over the index on demand, whereas the aggregation operator geoNear builds up the result in memory. Speed wise there is not going to be much of a difference, but memory wise you'd likely be better off using the query operator geoNear. If you don't need many documents than the difference is negligible.

    geoNear (aggregation) does have the possibility to also add the distance to the returned document, something that the query operator doesn't support.