I've a collection Users which looks something like this-
{ "post": "teacher",
"salary": 4500
},
{ "post": "teacher",
"salary": 9000
},
{ "post": "principal",
"salary": 7000
},
{ "post": "teacher",
"salary": 4500
}
I want to calculate the total salary of all the teachers together and the same way for principals. So I want something which looks like
"teachers_salary": 18000
"principals_salary": 7000
I want to use aggregation but I'm not getting the desired output. It'd be really helpful if anyone of you can help me get a solution to this.