It processes documents through a pipeline of stages, where each stage transforms the documents before passing them to the next
The aggregation framework is MongoDB’s built-in way to do multi-document analysis like this — counting, grouping, transforming and filtering in one pipeline.
Aggregation Framework in MongoDB works very much like an RxJS pipeline, but for database documents. Pipeline stages are like RxJS operators, Documents flow through the pipeline like events through a stream and Each stage outputs a new transformed stream of documents to the next stage. In MongoDB’s Aggregation Framework, the stream is inside the database engine, so it’s usually much faster because it avoids network round-trips and leverages DB indexes.