It looks like mongodb offers two similar functions for geospatial queries - $near
and $geoNear
. According to the mongo docs
The
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