Aggregation framework
In this type of queries the results of several partial queries are merged and grouped together to form a new result. The following query returns a list of all US states, that have more than 10 million inhabitants.
[
{Â
$group : {Â
_id : "$state",
totalPop : {Â
$sum : "$pop"
}Â
}Â
},
{Â
$match : {Â
totalPop : {
$gte : 10000000
}Â
}
}
]
The queries must be embedded in an array. Are the appropriate braces left out, it leads to an error message.
A detailed documentation of the MongoDB AggregationFramework can be found here: http://docs.mongodb.org/manual/core/aggregation-introduction/