我正在我的'用户'集合上运行一个聚合,以分配一个在用户坐标半径范围内的城市列表.
似乎没有办法将let变量分配给maxDistance
字段,因为这只能接受原始数字.
有没有其他方法可以不用$geoNear
或$geoWithin
来做同样的计算,因为这两种方法都有相同的限制.
$lookup: {
from: 'cities'
let: {
userCoordinates: '$coordinates',
userSearchRadius: '$searchRadius'
},
pipeline: [
{
$geoNear: {
near: {
type: "Point",
coordinates: '$$userCoordinates'
},
distanceField: 'distance',
maxDistance: '$$userSearchRadius', // Issue here
spherical: true,
}
}
],
as: 'nearbyCities'
}