MongoDB | Geospatial Query Additional Notes

By October 6, 2021MongoDB Learning

$near returns "nearest" as the naming suggests. And funny enough $geoWithin means "within the specified boundaries". In short, $near "sorts" the results to return, and that is always going to take more time than not sorting. So it depends on what you want. If "order" of "nearest" is important, then you use $near. If it is not, then use $geoWithin and a plain definition of a circle. Which is the only polygon the two share in common.