我正在尝试提取多边形(规则或不规则)内的所有元素,但 mongoDB 地理空间不起作用。
当我像这样进行查询时,效果很好
db.getCollection('houses').find({
'coordinates_geojson.coordinates.1': {
'$lte': 20.49584842128357,
'$gte': 20.458539491985142
},
'coordinates_geojson.coordinates.0': {
'$lte': -103.4088134765625,
'$gte': -103.47747802734375
}
})
但如果尝试使用 查询geoWithin
,则不会返回任何内容
db.getCollection('houses').find({
"coordinates_geojson": {
"$geoWithin": {
"$geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-103.47747802734375,
20.458539491985142
],
[
-103.4088134765625,
20.458539491985142
],
[
-103.4088134765625,
20.49584842128357
],
[
-103.47747802734375,
20.49584842128357
],
[
-103.47747802734375,
20.458539491985142
]
]
]
]
}
}
}
})
欢迎任何帮助或想法