• The aggregation pipeline consists of stages, and each stage transforms the document in MongoDB.
  • In each state, the documents are taken as input and produce the resultant set of documents are now in the next stage (id available) the resultant documents taken as input and produce output, this process is going on till the last stage.
  • In other word, the aggregation pipeline is a multi-stage pipeline.
  • The basic pipeline stages provide filters that will perform like queries and the document transformation modifies the resultant document, and the other pipeline provides tools for grouping and sorting documents.
  • In aggregation, there are various functions used:

Sum :

  • This aggregation function is used to sum numeric values for the document in each group.

Count :

  • This aggregation function is used to count total number of documents.

Average :

  • This aggregation function is used to calculates the average of all given values from all documents.

Minimum :

  • This aggregation function is used to get the minimum value from all the documents.

Maximum :

  • This aggregation function is used to get the maximum value from all the documents.

First :

  • This aggregation function is used to get the first document from the grouping.

Last :

  • This aggregation function is used to get the last document from the grouping.

Categorized in: