Spring Data 1.3.0.RC1 tersedia dan mendukung kerangka kerja agregasi.
Misalnya:Perintah agregasi shell:
db.eft_transactions.aggregate(
{$match:
{
service:"EFT",
source:"MARKUP",
}
},
{$group:
{
_id:"$card_acceptor_id",
tran_count:{$sum:1},
amount_sum:{$sum:"$amount"}
}
}
)
dijalankan seperti ini dari 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);
Dokumentasinya adalah disini
CATATAN:Kami baru-baru ini harus beralih menggunakan build BUILD-SNAPSHOT versi 1.3.0. Perubahan ini mengharuskan perubahan ke 2 baris di atas yang telah berubah menjadi:
AggregationOperation group = Aggregation.group("card_acceptor").sum("amount").as("amount_sum").count().as("tran_count");
Aggregation aggregation = Aggregation.newAggregation(match, group);