【发布时间】:2021-11-30 04:43:00
【问题描述】:
我有一个 mongodb 查询
[
{$group: {
_id: '$status',
count: {$sum: NumberInt(1)}
}}
]
查询返回如下结果:
[
{ _id: "A", count: 22 },
{ _id: "B", count: 33 },
{ _id: "C", count: 44 }
]
基于上述,我需要添加一个新字段“totalCount”(例如 22 + 33 + 44 = 99),如下所示:
[
{ _id: "A", count: 22, totalCount: 99 },
{ _id: "B", count: 33, totalCount: 99 },
{ _id: "C", count: 44, totalCount: 99 }
]
非常感谢任何帮助或线索。
【问题讨论】: