amit kumar :
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]
Saravana :
It Should be
Aggregation.group("company").count().as("count");