Aggregation Pipeline

MongoDB is not just adding and filtering data using find()

Aggregation is a way of processing a large number of documents in a collection by means of passing them through different stages.

The stages make up what is known as a pipeline. The stages in a pipeline can filter, sort, group, reshape and modify documents that pass through the pipeline

  • $match stage – filters those documents we need to work with, those that fit our needs

  • $group stage – does the aggregation job

  • $sort stage – sorts the resulting documents the way we require (ascending or descending)

Last updated