2011-09-21 46 views
0

我有一个属性“位置”的2d地理空间索引。我试图查询某个纬度/经度位置给定范围内的某些实体。如果我使用geoNear命令,我会得到正确的结果:MongoDB - 地理空间距离问题

distances = db.runCommand({ geoNear: "Places", near: [40.423776,-3.711534], spherical: true, maxDistance: 10/6378}).results 

输出给定坐标10公里范围内的所有地方。

但如果我执行以下查询我没有得到任何结果:db.Places.find({location: { $near [40.423776,-3.711534], $maxDistance: 10/6378, $nearSphere: true }})

难道我做错了什么?

回答

5

$ nearSphere应该这样来使用

db.Places.find({location:{$nearSphere:[[40.423776,-3.711534],10/6378]}}).count() 

希望它可以帮助