Spring Data 1.3.0.RC1 is available, and it supports an aggregation structure.
For example: Shell Aggregation Combination:
db.eft_transactions.aggregate( {$match: { service:"EFT", source:"MARKUP", } }, {$group: { _id:"$card_acceptor_id", tran_count:{$sum:1}, amount_sum:{$sum:"$amount"} } } )
runs as follows from java:
AggregationOperation match = Aggregation.match(Criteria.where("service").is("EFT").and("source").is("MARKUP")); AggregationOperation group = Aggregation.group("card_acceptor").and("amount_sum").sum("amount").and("tran_count").count(); Aggregation aggregation = newAggregation(match, group); AggregationResults<StoreSummary> result = this.mongoTemplate.aggregate(aggregation, "eft_transactions", StoreSummary.class);
Documentation here
NOTE. Recently we had to switch to using the BUILD-SNAPSHOT build version 1.3.0. This change required a change to the two above lines, which changed to:
AggregationOperation group = Aggregation.group("card_acceptor").sum("amount").as("amount_sum").count().as("tran_count"); Aggregation aggregation = Aggregation.newAggregation(match, group);
Ron tuffin
source share