开发者

MongoDB - Geospatial distance problem

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜