目前我花了一個小時試圖弄清楚我的查詢有什麼問題。Mongo 3.0,地理空間數據和計算距離
使用Mongo 3.0版本我有兩點,我檢查的不超過17000米。不幸的是,雖然試圖從距離達18000米的數據庫中獲得它們,但我一無所獲。
我試過 「2dsphere」 和/或 「2D」 指標:
db.location.ensureIndex({ position : "2dsphere" })
或
db.location.ensureIndex({ position : "2d" })
然後和我一起工作:
db.location.find({
position: { $near: [ 40.705395, -73.891104 ], $maxDistance: 18000 }
})
或
db.location.find({
position:
{
$near : {
$geometry : {
type : "Point" ,
coordinates : [ 40.705395, -73.891104 ]
},
$maxDistance : 18000
}
}
})
,並用:
db.location.find( { location : { $near : [ 40.705395, -73.891104 ], $maxDistance: 18000 } })
我:
Error: error: {
"$err" : "Unable to execute query: error processing query: ns=distance.location limit=0 skip=0\nTree: GEONEAR field=location maxdist=18000 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query",
"code" : 17007
}
實例文檔:
> db.location.find()
{ "_id" : ObjectId("5504ba8a97b3b27d56dc4045"), "id" : 123, "position" : [ 40.705562, -73.898818 ] }
老實說我找不到在哪裏我的問題是。數據庫計算似乎是錯誤的,但我寧願說我犯了一些錯誤。
你有沒有遇到過類似的情況?
你可以發佈帶有位置數據的示例文檔嗎? – ZeMoon 2015-04-05 17:04:13
@ZeMoon:我剛剛在 – Lormitto 2015-04-05 17:09:11