Reputation: 617
I have a 2d geospatial index on an attribute "location". I'm trying to query certain entities within a given range of a latitude/longitude location. If I use the geoNear command I get correct results:
distances = db.runCommand({ geoNear: "Places", near: [40.423776,-3.711534], spherical: true, maxDistance: 10/6378}).results
In outputs all the places within 10 km of the given coordinates.
But if I execute the following query I get no results: db.Places.find({location: { $near [40.423776,-3.711534], $maxDistance: 10/6378, $nearSphere: true }})
Am I doing something wrong?
Upvotes: 0
Views: 919
Reputation: 65877
$nearSphere should be used like this
db.Places.find({location:{$nearSphere:[[40.423776,-3.711534],10/6378]}}).count()
Hope it helps
Upvotes: 5