near()'s maxDistance seems to be being ignored
See original GitHub issueHey there,
I’m trying to write a simple query in Mongoose that returns a number of nearby results that all have GeoJSON properties. However, I’m getting a different number of results from my Mongoose script to that of a query directly in mongo.
Here’s a raw Mongo script:
var conn = new Mongo(),
db = conn.getDB("my_db"),
collection;
collection = db.my_moodels.find({
geo: {
$nearSphere: {
$geometry: {
type: "Point",
coordinates: [-0.02028, 51.50703]
},
$maxDistance: 3000 // 3k I'm assuming
}
}
});
print(collection.length()); // I get 6 (which is round about right)
Here’s my Mongoose script:
MyModel
.find()
.where('geo')
.near({
center: [-0.02028, 51.50703],
maxDistance: 3000,
spherical: yes
})
.exec(function (err, results) {
if (err) {
throw err;
} else {
console.log(results.length); // Here I get over 340, which I think is all of the possible results.
}
});
As you can see, the result count is entirely different. In fact, changing the maxDistance property in the Mongoose script seems to do nothing.
I’ve also found that putting the query directly in to the find()
method brings back the correct amount of results:
MyModel
.find({
geo: {
$nearSphere: {
$geometry: {
type: "Point",
coordinates: [-0.02028, 51.50703]
},
$maxDistance: 3000
}
}
})
.exec(function (err, results) {
if (err) {
throw err;
} else {
console.log(results.length); // Now I get 6
}
});
Is there a problem with using the near()
method or am I using it wrong?
Issue Analytics
- State:
- Created 9 years ago
- Comments:13
Top Results From Across the Web
$geoNear aggregation ignoring maxDistance - Stack Overflow
I solved it with following query: $geoNear: { near: { type: 'Point', coordinates: [lng, lat] }, distanceField: 'dist', limit: limit, ...
Read more >chrony.conf(5) Manual Page - TuxFamily
When a pool source is unreachable, marked as a falseticker, or has a distance larger than the limit set by the maxdistance directive,...
Read more >How to Deal With Being Ignored | Relationship Coach Online
1. Your partner may simply need some space to collect their thoughts and deal with their own emotions. Give them time and work...
Read more >Scripting API: Physics.Raycast - Unity - Manual
The max distance the ray should check for collisions. layerMask, A Layer mask that is used to selectively ignore Colliders when casting a...
Read more >Why Being Ignored Hurts So Much | Psychology Today
Research finds that feeling ignored can affect people's sensory perceptions, such as feeling that surroundings seem quieter.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed nothing wrong with
$near
or$maxDistance
. The problem was elsewhere in my code. Sorry! 🐑Thanks for pointing that out. I’ll try that now. However, the query examples for
geoJSON
data with2dsphere
indexes do show$maxDistance
as a sub-key of$near
. https://docs.mongodb.com/manual/reference/operator/query/near/#query-on-geojson-dataAfter fooling around in the past few days, I am now almost completely sure the problem is in my code.