$centerSphere 未返回任何 geojson 多边形 (mongoDB)

$centerSphere is not returning any geojson polygons (mongoDB)

我在处理以下 Mongo 查询时遇到了很多麻烦

location: { $geoWithin: { $centerSphere: [[lon,lat],radians] } }

它仅 returns geoJSON 指向并出于某种原因忽略了我所有的 geoJSON 多边形。 documentation 状态:

You can use the $centerSphere operator on both GeoJSON objects and legacy coordinate pairs.

我正在使用 Mongoose 来 运行 查询,我的 geoJSON 由 NPM 模块 wellknown 从 WellKnown Text 中隐藏。这是我的 geoJSON 在知名模块转换后的样子:

 "location": {
    "coordinates": [
        22.1,
        33.3
    ],
    "type": "Point"
}

"location": {
    "coordinates": [
        [
            [
                43,
                30
            ],
            [
                40,
                28
            ],
            [
                49,
                27
            ],
            [
                43,
                30
            ]
        ],
        [
            [
                44,
                28
            ],
            [
                44.7,
                28.8
            ],
            [
                46,
                28
            ],
            [
                44,
                28
            ]
        ]
    ],
    "type": "Polygon"
}

我的 Mongoose 架构定义为:

location: {
  type: schema.Types.Mixed,
  index: '2dsphere',
  required: false
}

我应该补充一点,withinPolygon 方法按预期工作,我得到了返回的点和多边形。以下工作完全正常:

location: { $geoWithin: { $geometry: geoJSON } }

感谢您的帮助。我已阅读文档,但在任何地方都看不到它提到 $centerSphere 仅 returns geoJSON 点。

随着最近发布的 MongoDB 版本 3.6.0-rc0,您现在可以使用 $geoWithin geospatial operator $centerSphere 查询 GeoJSON LineStrings 和 Polygons。

另请参阅 SERVER-27968 有关更新的更多信息。