通过aggregation进行分组查询,有时候需要统计查询记录总条数假设分组字段为day。如果查询函数写为:
{ $group: { _id: "day", count: { $sum: 1 } } }
那么查询出来的数量为记录条数,结果如图所示:
如果查询函数写为:
{ $group: { _id: "$day", count: { $sum: 1 } } }