Aggregation Framework Reference¶
Java Driver and Aggregation Framework¶
Let’s use a simple example to demonstrate how the aggregation helper works. Suppose I am using MongoDB to store my employee’s travel expenses. I’ve created a collection named
I am auditing three departments: Sales, Engineering and Human Resources. I want to calculate each department’s average spend on airfare. I’d like to use the Aggregation Framework for the audit, so I think of the operation in terms of a pipeline:
- Operation: Match documents where
type = "airfare"; then pipe into - Operation: Pass only the
department and the amount fields through the pipeline; then pipe into - Operation: Average the expense
amount, grouped by department.
I will use the aggregation operators
-
First operation:
-
Piped into:
-
Piped into:
Let’s take a look at the results of my audit: