云函数Aggregate.geoNear的minDistance和maxDistance不起作用,超出了maxDistance的结果还是被查询出来了。
app.router("NearShops", async (ctx, next) => {
const result = await db.collection('ShopAdmin')
.aggregate()
.geoNear({
spherical: true,
near: db.Geo.Point(event.longitude, event.latitude),
query: {
adminType: _.in(['Super', 'General']),
app: _.elemMatch({
type: _.eq('Recommend'),
isEnd: _.eq(1),
})
},
minDistance: 1000,
maxDistance: 5000,
distanceField: 'distance',
distanceMultiplier: 6378137,
key: 'location',
includeLocs: 'location',
}).lookup({
from: 'Shop',
let: {
shopId: '$shopId',
},
pipeline: $.pipeline()
.match(_.expr($.eq(['$_id', '$$shopId'])))
.project({
_id: 0,
app: 0
}).done(),
as: 'shopInfo',
}).replaceRoot({
newRoot: $.mergeObjects([$.arrayElemAt(['$shopInfo', 0]), '$$ROOT'])
}).project({
shopInfo: 0
}).lookup({
from: 'Goods',
let: {
goods: '$goods',
},
pipeline: $.pipeline()
.match(_.expr($.in(['$_id', '$$goods'])))
.sample({
size: 2
}).project({
imgUrl: 1,
}).done(),
as: 'partGoods',
}).end();
ctx.body = { data: result.list }
});