After utilizing the $near
command to fetch a list of cities near my current coordinates, I realized that there is an issue. It seems that you can be on the outskirts of a large city but still be closer to the center of the neighboring city than to where you are currently located. To address this, I am interested in incorporating population data into the results to accurately determine city size.
Villages.find({loc: {$near: [lat,long], $maxDistance: 2}},
{fields: {name: 1, _id: 0}},
{limit: 1}
);
Since it doesn't seem feasible to achieve this using $near
, I'm considering manually selecting the nearest cities and factoring in their populations. Would appreciate guidance on how best to approach this task, possibly by implementing haversine or other methods for accurate results?