What is aggregation?

The main purpose of aggregation operations is to refine query results by grouping together field values from multiple documents, and then performing one or more transformations. Aggregation in MongoDB can be as simple as presenting the results of a query into a set of one or more fields, or as complex as performing a multistage query, breaking the output into buckets, and performing operations on each result set. A more advanced usage would be to manipulate complex fields within a document. For example, if a document contains an array as one of its fields, an aggregation pipeline could be used to filter the output from this array.

The closest SQL equivalent to MongoDB aggregation would be the LIMIT, GROUP BY, and ORDER ...

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.