Reputation: 1019
How can I convert this code to java? How to use aggregation framework in java ? Can anyone please help me out...
My java code:
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
My mongo shell code :
db.collection.aggregate([
{ "$project": {
"TOTAL_EMPLOYEE_SALARY": {
"$sum": "$employees.EMP_SALARY"
}
}}
])
Upvotes: 0
Views: 866
Reputation: 151072
So use a 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);
Upvotes: 1