收藏
回答

云开发的云函数中如何使用 aggregate 对不同的状态进行合计?

假如list表的记录如下:

[
  {
    _id:0,
    progress:70,
  },
  {
    _id:1,
    progress:20,
  },
  {
    _id:3,
    progress:20,
  },
  {
    _id:4,
    progress:20,
  },
  {
    _id:5,
    progress:70,
  },
]


在云函数中如何使用 db.collection('list').aggregate 一次性统计出 progress为70 和 progress为20 的总数,期望返回结果:

 {
  total_20:3,
  total_70:2
 }
最后一次编辑于  2021-06-16
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容