Member-only story

#55 MongoDB (part 4): Aggregation

Hang Nguyen
3 min readJun 18, 2022

--

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.

1.Number of people by country.

--

--

Hang Nguyen
Hang Nguyen

Written by Hang Nguyen

Just sharing (data) knowledge

No responses yet