liveBook · Manning

Aggregation framework

As explained in MongoDB 8.0 in Action, Third Edition

The aggregation framework is MongoDB's pipeline-based system for transforming, grouping, and computing results from document data.

The aggregation framework is MongoDB’s pipeline-based system for processing document data. Multistage pipelines filter, group, transform, calculate, and reshape records, passing each stage’s results to the next. section 1.3.1 section 6.0

Common pipeline capabilities include:

  • Filter documents with $match, then group them with $group for sums, averages, counts, or other calculations. section 6.6
  • Organize results with $sort and restrict processing with $limit. section 6.6
  • Reshape documents with $set, $addFields, $project, or $unset; use $unwind to process array elements separately. section 6.6
  • Combine related records with $lookup, or combine result sets with $unionWith. section 6.1
  • Support reporting, dashboards, data discovery, ELT transformations, real-time analytics, and advanced text or vector search. section 6.1

A reporting pipeline

A report can pass documents through $match to select relevant records, $group to calculate totals, $sort to organize the results, and $limit to restrict the returned set. Breaking the transformation into stages makes it easier to understand, maintain, and debug. section 6.0

[ { <stage> }, { <stage> }, { <stage> }, { <stage> }, ... ]

Use the pipeline skeleton to visualize the ordered sequence of aggregation stages. section 6.1

Table 6.1 MongoDB operators for common SQL operations

SQL terms, functions, and concepts

MongoDB aggregation operators

WHERE

$match

GROUP BY

$group

HAVING

$match

SELECT

$project, $set, $unset

LIMIT

$limit

OFFSET

$skip

ORDER BY

$sort

SUM()

$sum

COUNT()

$count, $sum, $sortByCount()

JOIN

$lookup

SELECT INTO NEW TABLE

$out

MERGE INTO TABLE

$merge

UNION ALL

$unionWith

Use the SQL comparison to map familiar operations such as WHERE, GROUP BY, JOIN, ORDER BY, and UNION ALL to MongoDB operators. section 6.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains multistage pipelines, major stages, accumulators, reshaping, joins, and search, without detailing operator internals.
Examples
Uses staged reporting, SQL operator mappings, collection joins, dashboards, ELT transformations, and real-time analytics as examples.
What you can do after
Apply it via MongoDB aggregation pipelines to filter, calculate, reshape, join, organize, and analyze document data.
How it connects
Connects filtering, grouping, joins, array processing, change streams, SQL GROUP BY, full-text search, and vector search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.