[ { 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展开数组和组,但当展开时,总数将增加,这不是我想要的。请帮帮我。