【发布时间】:2021-08-13 00:46:53
【问题描述】:
如何在 mongodb 中搜索一个区域内的所有地理点。
我的收藏有
{
"_id": {
"$oid": "5fa2a64d267b8309fe781d98"
},
"location": {
"coordinates": ["115.880453987155", "-31.925513609342207"]
}
}
我现在想搜索这些数据以查看用户是否在里面
顶部:-31.97127、115.98367 底部:-32.11739、115.85955
我已经尝试过运行
[
{
'$search': {
'location': {
'$geoWithin': {
'$geometry': {
'type': 'Polygon',
'coordinates': [
[
115.8455154208042, -31.97458396927722
], [
115.8830653531429, -31.97460201459856
], [
115.8823782261087, -31.94124526669114
], [
115.8498438592383, -31.9409449398814
], [
115.8455154208042, -31.97458396927722
]
],
'crs': {
'type': 'name',
'properties': {
'name': 'urn:x-mongodb:crs:strictwinding:EPSG:4326'
}
}
}
}
}
}
}
]
但得到错误Remote error from mongot :: caused by :: Query should contain either operator or collector
【问题讨论】:
标签: mongodb geolocation