如何将这段代码转换为java?如何在java中使用聚合框架?谁能帮帮我吗...
我的java代码:
Document update = new Document("$project",new Document("TOTAL_EMPLOYEE_SALARY",new Document("$sum","$employees.EMP_SALARY")));
AggregationOutput output = coll.aggregate(update); // throwing some error in eclipse
我的 mongo shell 代码:
db.collection.aggregate([
{ "$project": {
"TOTAL_EMPLOYEE_SALARY": {
"$sum": "$employees.EMP_SALARY"
}
}}
])
最佳答案
所以使用列表
:
List<Document> pipeline = Arrays.<Document>asList(
new Document("$project",
new Document("TOTAL_EMPLOYEE_SALARY",new Document("$sum","$employees.EMP_SALARY"))
)
);
AggregationOutput output = coll.aggregate(pipeline);
关于java - 如何使用文档和 mongo 聚合将 mongo shell 代码转换为 java 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787731/