【发布时间】:2021-07-14 13:21:28
【问题描述】:
我的收藏中有以下对象:
{
"_id":"test123",
"footprint":{
"type":"Polygon",
"coordinates":[
[
[10, 30], [20, 45], [38, 38], [43, 38], [45, 30], [10, 30]
]
]
}
}
在“footprint”属性上具有“2dsphere”类型的索引。
现在,我想实现地理空间查询“重叠”,由 PostGIS 中的 ST_Overlaps 实现:https://postgis.net/docs/ST_Overlaps.html。
由于 MongoDB 本身不支持“重叠”(仅在内部、相交和附近),根据上述定义,我应该返回 所有不完全在搜索区域内的重叠文档.
因此,我正在尝试执行以下过滤器:
{
"footprint":{
"$geoIntersects":{
"$geometry":{
"type":"Polygon",
"coordinates":[
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
},
"$not":{
"$geoWithin":{
"$geometry":{
"type":"Polygon",
"coordinates":[
[
[
41.62109375000001,
38.087716380862716
],
[
41.870727539062514,
37.998201197578084
],
[
41.72393798828124,
38.01268326428104
],
[
41.62109375000001,
38.087716380862716
]
]
]
}
}
}
}
}
但我收到以下错误:
can't parse extra field: $not: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [ [ [ 41.62109375000001, 38.08771638086272 ], [ 41.87072753906251, 37.99820119757808 ], [ 41.72393798828124, 38.01268326428104 ], [ 41.62109375000001, 38.08771638086272 ] ] ] } } }
经过几次测试,我似乎无法对同一属性执行第二个过滤器。
我错了吗?有什么解决办法吗?
谢谢
【问题讨论】:
标签: mongodb mongodb-query pymongo geojson