Mongoose near maxDistance doesn't seem to have an effect Mongoose near maxDistance doesn't seem to have an effect mongoose mongoose

Mongoose near maxDistance doesn't seem to have an effect


I see what you are missing here.

According to the mongodb docs maxDistance is in meters only if your center is GeoJSON object.

So when you query with maxDistance: 3000, your unit is radian, and you get all of the results. (Since radian difference cannot go up to 3000).

Here is a working query with mongoose's query builder, and in meters:

MyModel  .find()  .where('geo')  .near({    center: {type: 'Point', coordinates: [-0.02028, 51.50703]}, // <--    maxDistance: 3000,    spherical: yes  })  .exec(function (err, results) {    if (err) {      throw err;    } else {      console.log(results.length); // This should work.    }  });