For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Group and Total Data

This tutorial illustrates how to construct an aggregation pipeline, perform the aggregation on a collection, and display the results using the language of your choice.

This tutorial demonstrates how to group and analyze customer order data. The results show the list of customers who purchased items in 2020 and include each customer's order history for 2020.

The aggregation pipeline performs the following operations:

  • Matches a subset of documents by a field value

  • Groups documents by common field values

  • Adds computated fields to each result document

The following steps demonstrate how to create and run an aggregation pipeline to group documents and compute new fields.