【发布时间】:2014-07-10 07:13:14
【问题描述】:
我在 Mac OS X 上使用 MongoDB 2.6.1
我有一个locations 的集合,其中包含一个有效的GeoJSON 字段:
db.locations.findOne({}, {"location": 1})
{
1"_id" : ObjectId("534fd2b6b13e51768cd0e9c8"),
"location" : {
"type" : "Point",
"coordinates" : [
41.311,
56.3526
]
}
}
我的数据库中有2dsphere 索引:
db.locations.getIndexes()
[
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"ns" : "insta_locations.locations",
"name" : "location_2dsphere"
},
...
]
但是当我在没有提示的情况下查询位置时,我得到一个错误:
db.locations.find({
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [41.311, 56.35]
},
$maxDistance: 1
}
}
})
产生:
错误:{ "$err" : "找不到特殊索引: 2d for: { location: { $near: { $geometry: { type: \"Point\", 坐标: [ 41.311, 56.35 ] }, $maxDistance: 1.0 } } }", “代码”:13038 }
另一方面,它返回整个集合的提示:
db.locations.find({
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [41.311, 56.35]
},
$maxDistance: 1
}
}
}).hint('location_2dsphere').length()
5138
有谁知道我缺少什么才能使其正常工作?
更新
> version()
2.6.1
> db.version()
2.2.2
【问题讨论】:
-
你能在你的 mongo shell 中运行 version() 和 db.version() 并将输出添加到问题中吗?
-
看来是这个原因。如何升级数据库本身?