Member-only story
#55 MongoDB (part 4): Aggregation
Aggregation operations process multiple documents and return computed results. You can use aggregation operations to:
- Group values from multiple documents together.
- Perform operations on the grouped data to return a single result.
- Analyze data changes over time.
To perform aggregation operations, you can use:
1. Aggregation pipelines, which are the preferred method for performing aggregations.
2. Single purpose aggregation methods, which are simple but lack the capabilities of an aggregation pipeline.
Aggregation Pipelines
An aggregation pipeline consists of one or more stages that process documents:
- Each stage performs an operation on the input documents. For example, a stage can filter documents, group documents, and calculate values.
- The documents that are output from a stage are passed to the next stage.
- An aggregation pipeline can return results for groups of documents. For example, return the total, average, maximum, and minimum values.
Aggregation in practice
Let’s practice with aggregation continued from part 3. Please refer to the setup and dataset in my previous blog post.