我在mongodb上有以下聚合工作,但我没想出如何在Spring Data上复制它。
db.pedido.aggregate( [
{ $unwind: "$items" },
{ $project: { itemValue: { $multiply: [ "$items.price", "$items.quantity"] } } },
{ $group: { _id: "$_id", orderValue: { $sum: "$itemValue" } } },
{ $match: { orderValue: { $gte: 150 } } }
] )
我尝试过这样的事情,
Aggregation agg = Aggregation.newAggregation(Order.class,
project("items"),
unwind("items"),
project("items.price", "items.quantity").and("items.price").multiply("items.quantity").as("itemValue"),
group("_id").sum("itemValue").as("orderValue"),
match(where("orderValue").gte(150))
);
return operations.aggregate(agg, Order.class, Order.class).getMappedResults();
但是我得到了java.lang.IllegalArgumentException:无效的引用“价格”! Spring Aggregation有什么问题?有什么方法可以使用@Query方法使用mongodb聚合,或者其他方式来做到这一点?
我正在使用MongoDB 3.2和spring-data-mongodb 1.9.1.RELEASE