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
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 ...