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?
$nearSphere should be used like this
db.Places.find({location:{$nearSphere:[[40.423776,-3.711534],10/6378]}}).count()
Hope it helps
精彩评论