My following mongodb query works as expected
db.importedDataItems.aggregate({
$match: {
mobile: "1234567890"
}
}, {
$group: {
_id: 'mobile',
calls: { $sum: '$calls' }
}
})
but even after referring to these questions & tutorial, its equivalent Java code...
Aggregation agg = Aggregation.newAggregation(Aggregation.match(Criteria.where("mobile").is("1234567890"),
Aggregation.group("mobile").sum("calls").as("totalCalls"),
Aggregation.project("totalCalls"));
AggregationResults<Doc> results = mongoTemplate.aggregate(agg, "yoCollection",
Doc.class);
Doc doc = results.getMappedResults().get(0);
...returns an empty list & throws IndexOutOfBoundsException
though my query returns results on console!