Database

[{id:"ID",points:10,sources:[{sourceId:"s1",sourcePoints:6},{sourceId:"s2",sourcePoints:4}]},{id:"ID",points:2,sources:[{sourceId:"s1",sourcePoints:2}]}]

Query

db.collection.aggregate([{$group:{_id:"$id",points:{$sum:"$points"},sources:{$push:"$sources"}}},{$addFields:{sources:{$function:{body:"function (sources) {\n const result = {};\nfor (let source of sources) {\n for (let detail of source) {\n if (result[detail.sourceId]) {\n const current = result[detail.sourceId].sourcePoints + detail.sourcePoints;\n result[detail.sourceId] = {sourcePoints: current};\n } else {\n result[detail.sourceId] = {sourcePoints: detail.sourcePoints};\n }\n }\n}\nreturn result;\n }",args:["$sources"],lang:"js"}}}}])

Result