> version()
version: 2.0.4
can't find special index: 2d for: { location: { $near: { $geometry: { type: "Point", coordinates: [ 0.1, 0.1 ] } }, $maxDistance: 5000.0 } }
> version()
version: 2.0.4
can't find special index: 2d for: { location: { $near: { $geometry: { type: "Point", coordinates: [ 0.1, 0.1 ] } }, $maxDistance: 5000.0 } }
> db.syncsnapshotsphere.find()
{ "_id" : "naga", "location" : { "type" : "Point", "coordinates" : [ 0.1, 0.1 ] }, "timestamp" : 1375778757.568005 }
{ "_id" : "nagb", "location" : { "type" : "Point", "coordinates" : [ 0.2, 0.2 ] }, "timestamp" : 1375778792.552187 }
{ "_id" : "nagc", "location" : { "type" : "Point", "coordinates" : [ 0.3, 0.3 ] }, "timestamp" : 1375778803.047879 }
{ "_id" : "nagd", "location" : { "type" : "Point", "coordinates" : [ 0.4, 0.4 ] }, "timestamp" : 1375778814.088595 }
> db.syncsnapshotsphere.find({location: {$near: {$geometry: {type: "Point", coordinates: [0.1,0.1]}}, $maxDistance: 5000}})
error: {
"$err" : "can't find special index: 2d for: { location: { $near: { $geometry: { type: \"Point\", coordinates: [ 0.1, 0.1 ] } }, $maxDistance: 5000.0 } }",
"code" : 13038
}
在第二行“版本......”之后很快看起来很奇怪的“找不到特殊索引......”实际上是输出......我不知道为什么。
我想弄清楚为什么我得到错误,说它正试图找到一个2d索引,其中2dsphere索引已经存在于位置字段...所有帮助表示赞赏。
> db.syncsnapshotsphere.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "logging_stuff.syncsnapshotsphere",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"ns" : "logging_stuff.syncsnapshotsphere",
"name" : "location_2dsphere",
"background" : false,
"dropDups" : false
}
]
>
答案 0 :(得分:1)
2dsphere
是MongoDB 2.4中引入的索引类型,您使用的是2.0.4。因为您正在使用2.0.x进行地理查询,所以MongoDB需要2d
索引。请将MongoDB升级到2.4.x,这样就可以了。