I have these documents.
[
{
_id: 'a1',
sales: [
{
amont: 12,
servicer_id: 'A',
},
{
amont: 10,
servicer_id: 'B',
},
],
service: [
{
amont: 25,
servicer_id: 'A',
},
{
amont: 20,
servicer_id: 'B',
},
],
},
{
_id: 'a2',
sales: [
{
amont: 10,
servicer_id: 'A',
},
{
amont: 20,
servicer_id: 'B',
},
],
service: [
{
amont: 15,
servicer_id: 'A',
},
{
amont: 10,
servicer_id: 'B',
},
],
},
]
From the above document, I want to find the following.
1.Number of the service done by both servicer A and B.
2.Number of the sales done by both servicer A and B.
3.Total service amount of servicer A and B.
4.Total sales amount of servicer A and B.
Expected Output
[
{
servicer: 'A',
services: 2,
sales: 2,
totalSale: 22,
totalService: 40,
},
{
servicer: 'B',
services: 2,
sales: 2,
totalSale: 30,
totalService: 30,
},
];