var {community, location}=that,
{dynamic}=community,
{longitude, latitude}=location,
maxDistance=data.maxDistance||50000,
geoNear = {
distanceField: 'distance',
spherical: true,
near: new db.Geo.Point(longitude, latitude),
query: {
offShelves:_.neq(true)
},
maxDistance
};
console.log(maxDistance)
dynamic.status='loading';
db.collection('xn-user-action').aggregate().geoNear(geoNear).lookup({
from: 'xn-community',
let: {
id: '$communityID',
},
pipeline: $.pipeline().match(_.expr($.eq(['$_id','$$id']))).project({public:1, name:1}).done(),
as: 'community'
}).lookup({
from: 'uni-id-users',
let: {
creator: '$creatorID',
},
pipeline: $.pipeline().match(_.expr($.eq(['$_id','$$creator']))).project({avatar_file:1,nickname:1}).done(),
as: 'creatorID'
}).match({
"community.0.public":_.neq(false)
}).limit(20).end().then(res=>{
let list=res.result.data;
if(list.length<20){
dynamic.status='nomore';
}else{
dynamic.status='loadmore';
};
resolve(list);
}).catch(err=>{
reject(err);
})
1***@qq.com
- 发布:2021-09-27 17:57
- 更新:2021-12-27 11:13
- 阅读:636
最佳回复
重庆柔然科技 - 短头发
我也遇到这个问题,在云函数里面写的聚合查询,限制30公里以内,结果是1000公里以外的都查询出来了
async search(data, uid) {
const cmd = this.db.command;
let {
longitude,
latitude,
type,
} = data;
let result = await this.collection.aggregate()
.geoNear({
distanceField: 'juli', // 输出的每个记录中 distance 即是与给定点的距离
spherical: true,
near: new this.db.Geo.Point(longitude, latitude),
maxDistance: 30000, //限制30km
minDistance: 0,
query: {
isOnline: true,
type: type,
},
key: 'home_address.location', // 若只有 location 一个地理位置索引的字段,则不需填
includeLocs: 'home_address.location', // 若只有 location 一个是地理位置,则不需填
})
.project({
mobile: 0
})
.skip((data.page - 1) * data.limit)
.limit(data.limit)
.end()
return result.data;
}