2011-09-21 48 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() 

希望它可以幫助