我收到错误"无法从对象,格式错误的几何图形中提取地理位置键?"。多边形是关闭的,格式看起来很好,因为它正确插入Mongo。我使用的是Mongo 2.6.3版,在Centos 6.5 x64上运行。
下面的多边形有什么问题?我非常密切地关注了Mongo的例子。
db.test.remove({});
db.test.insert({testPoly: {type: "Polygon", coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]}});
db.test.ensureIndex({testPoly: "2dsphere" });
db.test.find();
/* 0 */
{
"connectionId" : 2385,
"err" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('54008301eb55d4628c080370'), testPoly: { type: \"Polygon\", coordinates: [ [ 0.0, 0.0 ], [ 0.0, 20.0 ], [ 10.0, 30.0 ], [ 20.0, 20.0 ], [ 20.0, 0.0 ], [ 0.0, 0.0 ] ] } }",
"code" : 16755,
"n" : 0,
"ok" : 1
}
/* 0 */
{
"_id" : ObjectId("54008301eb55d4628c080370"),
"testPoly" : {
"type" : "Polygon",
"coordinates" : [
[
0,
0
],
[
0,
20
],
[
10,
30
],
[
20,
20
],
[
20,
0
],
[
0,
0
]
]
}
}
答案 0 :(得分:7)
您在坐标中缺少数组级别:
coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]
应该是:
coordinates: [[[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]]