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:
本文通过实例演示如何使用MongoDB的聚合框架来计算不同部门的平均航空旅行费用。介绍了聚合操作符如$match, $project 和 $group 的具体用法,并提供了对应的MongoDB命令及Java实现。
533

被折叠的 条评论
为什么被折叠?



