So I have a collection like this:
{
'region': '1',
'status': 'a',
'sum': 100
}
{
'region': '1',
'status': 'b',
'sum': 80
}
{
'region': '2',
'status': 'a',
'sum': 20
}
{
'region': '2',
'status': 'a',
'sum': 30
}
And the desired result must be like this:
[
{
'region': '1',
'status_a': 1,
'status_b': 1,
'sum': 180
},
{
'region': '2',
'status_a': 2,
'sum': 50
}
]
Any suggestions? The number of regions as well as the number of statuses can vary and I need to always output the sum for the entire region despite statuses
P.S if you wanna be super specific with your answer, then region and status fields are ObjectId's, thanks in advice!