MongoDB | Geospatial Query Additional Notes

$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.

Built with Hugo
Theme Stack designed by Jimmy