Aggregation pipeline stages

The aggregation pipeline stages are represented by stage operators. In the following illustration, we formulate a command which has two stages. The first stage performs a match (see the discussion of the $match operator that follows), followed by a grouping stage (see $group). You can have as many or as few stages as desired. Each stage produces results which are put back into the pipeline, and subsequently processed by the next stage:

The discussion in this section summarizes key stage operators, which can be used in conjunction with the db.collection.aggregate() command. The examples shown here assume that there's ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.