目前我花了一个小时试图弄清楚我的查询有什么问题。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