Mongodb错误:无法从对象,格式错误的几何体中提取地理位置键?

apo*_*her 6 mongodb

我用mongodb 2.4.3得到以下错误

Can't extract geo keys from object, malformed geometry?

{type: "Polygon",
coordinates: [
    [
        [
            103.8324334524412,
            1.284232321447769
        ],
        [
            103.8342325475588,
            1.284232321447769
        ],
        [
            103.8342325469261,
            1.282433678236006
        ],
        [
            103.8324334530738,
            1.282433678236006
        ]
    ]
]}
Run Code Online (Sandbox Code Playgroud)

有人能帮助我理解这个问题吗?它看起来像一个有效的geoJSON对象.我的索引是类型的2dsphere.

我正在运行的两个步骤是:

collection.ensureIndex {'geometry' : "2dsphere"}, (error) =>
  # some error checking
  # and then
  collection.insert features, (error) =>
    # features is an array of geoJSON feature objects
    # {"type" : "Feature"
    #  "geometry" : <the Polygon object above>
      }
Run Code Online (Sandbox Code Playgroud)

insert查询会出现此错误.我想插入的完整文档是:

{
    "type":"Feature",
    "geometry": {
        "type":"Polygon",
        "coordinates":[
           [
             [103.83243345244122,1.2842323214477689],
             [103.83423254755876,1.2842323214477689],
             [103.83423254692615,1.2824336782360055],
             [103.83243345307383,1.2824336782360055]
           ]
        ]
      },
    "properties":{"name" : "My location"}
  }
Run Code Online (Sandbox Code Playgroud)

apo*_*her 9

geoJSON中的多边形对象要求第一个点([lon,lat])与最后一个点相同.通过进行此更改:

{type: "Polygon",
coordinates: [
    [
        [
            103.8324334524412,
            1.284232321447769
        ],
        [
            103.8342325475588,
            1.284232321447769
        ],
        [
            103.8342325469261,
            1.282433678236006
        ],
        [
            103.8324334530738,
            1.282433678236006
        ],
        [
            103.8324334524412,
            1.284232321447769
        ]
    ]
]}
Run Code Online (Sandbox Code Playgroud)

插入查询工作正常.