如何将此代码转换为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"
}
}}
])
答案 0 :(得分:1)
所以使用List
:
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);