How can I create a comprehensive country grouping with the total sum of subdetails/subdocuments?
[{
Country: 'USA',
amount: 10,
detailA: [{
Country: 'USA',
amount: 20,
},{
Country: 'MEX',
amount: 20,
},{
Country: 'RUSK',
amount: 30,
}],
detailB: [{
Country: 'USA',
amount: 90,
}]
},{
Country: 'RUSK',
amount: 30,
detailA: [{
Country: 'USA',
amount: 50,
},{
Country: 'MEX',
amount: 60,
}],
detailB: [{
Country: 'MEX',
amount: 10,
}]
}];
Desired output after grouping by country: USA 170 RUSK 60 MEX 90