mongodb 2dsphere索引在MultiPolygon(格式错误的几何体)上失败

时间:2018-02-11 14:51:38

标签: mongodb indexing geojson

我正在努力解决以下索引失败的原因:

> db.mycollection.ensureIndex({geometry:"2dsphere"})
{
        "err" : "Can't extract geo keys from object, malformed geometry?:{ type: \"MultiPolygon\", coordinates: [ [ [ [ -0.097262623621224, 51.52157883707353 ], [ -0.096489562220012, 51.52027612781475 ], [ -0.095242927823793, 51.52050373756695 ], [ -0.094744446266, 51.5205960952269 ], [ -0.094366848238175, 51.5206711083638 ], [ -0.094478602055745, 51.51976097300852 ], [ -0.095268219478419, 51.51892749907517 ], [ -0.095057671259463, 51.51823866169356 ], [ -0.09590752332937, 51.51675447483272 ], [ -0.094917254103398, 51.51658818255699 ], [ -0.095455170681833, 51.51544167621788 ], [ -0.09577124973446099, 51.51496874589772 ], [ -0.096562908994151, 51.5148429136635 ], [ -0.097957187488107, 51.51553859434178 ], [ -0.097828201440347, 51.51660172221631 ], [ -0.09972288755426, 51.5167693068687 ], [ -0.099643129935966, 51.51745174289048 ], [ -0.099140106492407, 51.51776283078856 ], [ -0.098174109996819, 51.51789906140922 ], [ -0.098017592779996, 51.5175476311896 ], [ -0.097562458108715, 51.51768194540703 ], [ -0.097737151858934, 51.519666041172 ], [ -0.0978402555155, 51.51992164186168 ], [ -0.098548930349501, 51.51973516284531 ], [ -0.098498300867191, 51.52053989289254 ], [ -0.09761991242012499, 51.52069031743765 ], [ -0.097262623621224, 51.52157883707353 ] ] ] ] }",
        "code" : 16572,
        "n" : 0,
        "connectionId" : 61,
        "ok" : 1
}

我在SO上检查了所有相关问题,但无法找出问题所在。他们都指出了lon,lat顺序和坐标的格式。我使用的是Mongodb 2.4。

可能有一种解释,但我不确定

MongoDB version 2.6 still fails on 2dsphere geoindexing citing inability to extract geokeys and possible malformed geometry

1 个答案:

答案 0 :(得分:0)

MongoDB 2.4不支持Multipolygon几何类型(参见Geospatial enhancements in MongoDB 2.6)。

请注意,在撰写本文时,MongoDB 2.4不再受支持。如果这是一个新项目,我建议使用最新版本(目前是MongoDB 3.6.2),以确保您不会受到新版本中修复的任何历史问题的影响。