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.One of the most common use cases of Aggregation is to calculate aggregate values for groups of documents. This is similar to the basic aggregation available in SQL with the GROUP BY clause and COUNT, SUM and AVG functions. MongoDB Aggregation goes further though and can also perform relational-like joins, reshape documents, create new and update existing collections, and so on.While there are other methods of obtaining aggregate data in MongoDB, the aggregation framework is the recommended approach for most work.There are what are called single purpose methods like estimatedDocumentCount(), count(), and distinct() which are appended to a find() query making them quick to use but limited in scope.
Here is a diagram to illustrate a typical MongoDB aggregation pipeline.
Source: https://studio3t.com/knowledge-base/articles/mongodb-aggregation-framework/
Update demo application to without login