云数据库聚合查询报错?

发布于 6 年前作者 khao8851 次浏览最后编辑 6 年前来自 ask

报错信息:$ is not defined

描述:在云开发数据库里可以查出来的

代码:

db.collection('result')

      .aggregate()

      .group({

        // 按 category 字段分组

        _id: '$_openid',

        // 每组有一个 avgSales 字段,其值是组内所有记录的 sales 字段的最大值

        top_score: $.max('$all_score'),

        name: $.max('$wechat_name'),

        date: $.max('$date')

      })

      .sort({

        top_score:-1

      })

      .end()

1 回复
chaoliu
chaoliu1 楼4 年前
const $ = db.command.aggregate