Question

Lets say one of my items in a collection looks like that:

{ User:123 Grade : 100 }

I want to sum up the grades for each student so i have this output:

123: 100, 445: 30 etc

Im normal sql, its the equivalent of a group by + sum() query. How can i do it with mongo?

Was it helpful?

Solution

You will have to use the mongodb aggregation framework.

Check this example: https://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top