MongoDB Aggregation Queries Basics on MongoLab
What is MongoLab? MongoLab is a hosted MonoDB service that offers one free database to developers wanting to learn the technology. It's a very elegant way to start learning or developing a small application. I started using this earlier in the year and had created a couple of collections on it. What is the MongoDB Aggregation Framework? Traditionally in SQL databases you have the concept of a GROUP BY and an aggregation function like average or sum. In MongoDB, aggregation wasn't ever as easy, in order to do any aggregation you'd have to write your own complicated MapReduce jobs. Along comes MongoDB version 2.2 , which includes the aggregation framework. So consider this SQL statement: SELECT sum(duration) FROM calls GROUP BY disposition And here it is translated to MongoDB, I've attempted to color code the translations: } runCommand: { aggregate : 'calls', pipeline : [ { $group : { ...