我的模式有点像:
...
...
pointA: GeoJSON point
pointB: GeoJSON point
...
...
我正在传递两个参数,一个地理点(x)和一个地理点数组(y),并且只想返回那些符合以下条件的结果:
-> x
和pointA
之间的距离不应大于1000m。
->数组y
的任何一点都应位于pointB
的100m之内。
不幸的是,似乎MongoDB不支持将多个$ geoNear查询一起管道传输
以下代码
Collection
.aggregate([
{
$geoNear: {
distanceField: "calculatedDistance",
spherical: true,
maxDistance: 1000,
near: x,
key: "pointA.coordinates"
}
},
{
$or: [
{
$geoNear: {
spherical: true,
maxDistance: 100,
key: "pointB.coordinates",
near: {
type: "Point",
coordinates: y[0]
},
distanceField: "calculatedDistanceB"
}
},
...
...
...
...
{
$geoNear: {
spherical: true,
maxDistance: 100,
key: "pointB.coordinates",
near: {
type: "Point",
coordinates: y[i]
},
distanceField: "calculatedDistanceB"
}
}
]
}
])
显示错误$geoNear is only valid as the first stage in a pipeline.
如何在单个查询中执行多个地理空间检查?