I am unable to query a mongodb database using mongoose\'s qry.where().near()
syntax.
I have a Schema with coordinates stored as an array, indexed as
Seems this is a moongoose bug.
Changing the query to use a GeoJSON
object instead of a coordinate pair, as such:
qry.where('loc').near({
center: {
type: 'Point',
coordinates: search.loc
},
maxDistance: search.distance * 1000
});
results in the following query:
Mongoose: models.find({ loc: { '$near': {
'$maxDistance': 1,
'$geometry': { type: 'Point', coordinates: [ 10, -20 ] } } }
}) { fields: undefined }
The search now succeeds.
The docs explicitly show a query using a coordinate pair:
query.where('loc').near({ center: [10, 10], maxDistance: 5 });
However, it looks like this doesn't work, and the example should be:
query.where('loc').near({ center: { coordinates: [10, 10], type: 'Point' }, maxDistance: 5 });