O'Reilly logo

MongoDB: The Definitive Guide, 3rd Edition by Kristina Chodorow, Shannon Bradshaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Introduction to the Aggregation Framework

Many applications require data analysis of one form or another. MongoDB provides powerful support for running analytics natively using the aggregation framework. In this chapter, we introduce the aggregation framework and some of the fundamental tools this framework provides:. In the next chapter, we’ll dive deeper, looking at more advanced aggregation features, including the ability to perform joins across collections.

  • The aggregation framework

  • Aggregation stages

  • Aggregation expressions

  • Aggregation accumulators

Pipelines, Stages, and Tunables

The aggregation framework is a set of analytics tools within MongoDB that allow you to do analytics on documents in one or more collections.

The aggregation framework is based on the concept of a pipeline. The idea with an aggregation pipeline is that we take input from a MongoDB collection and pass the documents from that collection through one or more stages, each of which performs a different

operation on its inputs. Each stage takes as input whatever the stage before it produced as output. The inputs and outputs for all stages are documents -- a stream of documents, if you will.

If you’re familiar with pipelines in a Linux shell, such as bash, this is a very similar idea. Each stage has a specific job that it does. It’s expecting a specific form of document and produces a specific output, which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required