Its fairly an easier Pipeline :
db.collection.aggregate([
{
"$match": {
"companyId": ObjectId("635c70892e8cfaf4a7d49a3f")
}
},
{
"$unwind": {
"path": "$datas"
}
},
{
"$unwind": {
"path": "$datas.report"
}
},
{
"$unwind": {
"path": "$datas.report.scores"
}
},
{
"$group": {
_id: "$datas.report.scores.key",
sum: {
$sum: "$datas.report.scores.value"
}
}
}
])
Thanks
Pavel