You can create multiple stages within the aggregation by simply adding a new document to the list of arguments presented to the aggregate() method. Each document in the list must start with a pipeline stage operator. Here is a summary of the more important pipeline stage operators:
Operator | Notes |
$bucket | Creates sub-groups based on boundaries, which allow further, independent processing. As an example, you could create a revenue report with buckets consisting of $0.00 to $1.000, $1,001 to $10,000, $10,001 to $100,000, and more. |
$count | Returns the number of documents at this stage in the pipeline. |
$geoNear | Used for geospatial aggregation. This single operator internally leverages $match, $sort, and $limit. |
$group | Produces a single document that has an accumulation of all the documents with the same value for the field identified as _id. |
$lookup | Incorporates documents from other collections in a similar manner to an SQL LEFT OUTER JOIN. |
$match | Serves... |