An analysis and summary of data
A series of stages completed one at a time, in order
db.collection.aggregate([
{
$stage1: {
{ expression1 },
{ expression2 }...
},
$stage2: {
{ expression1 }...
}
}
])
An aggregation operation performed on the data
The $match
stage filters for documents that match specified conditions.
syntax:
{
$match: {
"field_name": "value"
}
}
$group
stage groups documents by a group key.syntax:
{
$group:
{
_id: <expression>, // Group key
<field>: { <accumulator> : <expression> }
}
}
match
& group
The $sort
stage sorts all input documents and returns them to the pipeline in sorted order. We use 1 to represent ascending order, and -1 to represent descending order.