Member-only story
Spring Data Reactive MongoDB aggregation pipeline
In this story, we’ll explain how to use MongoDB Aggregation Framework with Spring Data Reactive MongoDB.

· Prerequisites
· Overview
∘ MongoDB Aggregation Framework
∘ How does the MongoDB Aggregation Framework work?
· Aggregation pipeline in Spring Reactive
∘ Project Setup
∘ With @Aggregation Annotation
∘ Aggregation With ReactiveMongoTemplate
· Testing
· Conclusion
· References
Prerequisites
This is the list of all the prerequisites for following this story:
- Java 17
- Starter WebFlux 3.1.0
- Maven 3.6.3
- Mongo 4.4 installed
- Postman or Insomnia
Overview
MongoDB Aggregation Framework
The aggregation pipeline is a framework for data aggregation modeled on the concept of data processing pipelines. It’s a way to query documents from MongoDB in a way that breaks down these more confounding queries. It separates complex logic into sequential operations.
Aggregation in MongoDB allows for the transforming of data and results in a more powerful fashion than from using the find() command.
How does the MongoDB Aggregation Framework work?
MongoDB Aggregation Framework builds a pipeline using multiple stages and expressions to perform analytic operations.
In the aggregation Framework, we think of stages instead of commands. Each stage performs an operation on the input documents. For example, we can build an aggregation pipeline that matches a set of documents based on a set of criteria, groups those documents together, sorts them, then returns that result set to us.