收藏
回答

云函数Aggregate.geoNear的minDistance和maxDistance不起作用?

框架类型 问题类型 终端类型 AppID 环境ID 基础库版本
小程序 Bug 微信iOS客户端 wx41074a0da4ff88ae ohho-0g07i44qa70ce331 2.21

云函数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 }
  });
回答关注问题邀请回答
收藏
登录 后发表内容
问题标签