Spring Data 1.3.0.RC1 è disponibile e supporta l'aggregation framework.
Ad esempio, il comando di aggregazione della shell:
db.eft_transactions.aggregate( {$match: { service:"EFT", source:"MARKUP", } }, {$group: { _id:"$card_acceptor_id", tran_count:{$sum:1}, amount_sum:{$sum:"$amount"} } } )
si esegue così da 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);
La documentazione è qui.
NOTA: di recente abbiamo dovuto passare alla build BUILD-SNAPSHOT della versione 1.3.0. Questo ha reso necessaria la modifica a 2 delle righe sopra, che ora sono:
AggregationOperation group = Aggregation.group("card_acceptor").sum("amount").as("amount_sum").count().as("tran_count"); Aggregation aggregation = Aggregation.newAggregation(match, group);