I have the following dataset, which contains marks for a student's test. However, each mark is stored in a separate object for each question of the test, like this:
{
school: A,
question: 1,
student: 1,
test: Summer Test,
mark: 0,
},
{
school: A,
question: 2,
student: 1,
test: Summer Test,
mark: 1,
},
{
school: A,
question: 3,
student: 1,
test: Summer Test,
mark: 2,
},
How can I use a mongo aggregate to calculate how many marks a student got for a particular test by adding up all the individual marks? Then group by school?
So the result would look like this:
**school A**
{
Summer Test {
students: {student 1 = 3 marks; student 2 = 0 marks; student 3 = 2 marks}
}
Winter Test {
students: {student 1 = 2 marks; student 2 = 1 marks; student 3 = 3 marks}
}
}
And so on for each school? Could anyone give me some advice on how to go about this? Many Thanks