【发布时间】:2023-02-16 18:01:53
【问题描述】:
[
{
providers: [
{
code: 1
},
{
code: 1
},
]
},
{
providers: [
{
code: 2
},
{
code: 1
},
{
code: 2
}
]
},
]
我有这样的文件
并希望获得如下结果:
[
{
"code": 1,
"total": 2 (because it appear in two item of the array)
},
{
"code": 2,
"total": 1 (because it appear in just the second item of the array)
}
]
我尝试使用 $sum: 1 展开数组和分组,但是当展开时,总数会增加,这不是我想要的。请帮我。
【问题讨论】: