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?

  • 2
    Have you looked at the documentation? The examples look pretty clear to me.
    – Tom V
    Dec 16, 2015 at 12:10

1 Answer 1


You will have to use the mongodb aggregation framework.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.