3

I am using GroupOperation in java to group a field and count the value but I am not getting the desired result.

I am using Mongo Operation to connect with MongoDB using Java. I am able to group on the basis of field "company" but the count remains 0 always. I am not able to figure out the reason for this.

GroupOperation 
group=Aggregation.group("company").sum("company").as("count");
    Aggregation aggregation=Aggregation.newAggregation(group);
    AggregationResults<ResultMap> orderAggregate = 
mongoOperations.aggregate(aggregation,EmpDesc.class,ResultMap.class);

orderAggregate.getMappedResults().forEach(s->System.out.println("^^ 
"+s.toString()));

Always getting:

 ResultMap [company=ABC, count=0]
 ResultMap [company=XYZ, count=0]

1 Answer 1

3

It Should be

Aggregation.group("company").count().as("count");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.