1.统计一个内嵌集合里面的金额总计:sum(mioLogList.amnt)
Aggregation sumJeAgg = Aggregation.newAggregation(
Aggregation.match(Criteria.where("applNo").is("4140427596704768").and("isInValid").is("1")),//条件Aggregation.unwind("mioLogList"), //将子集合拆分成开
Aggregation.group("sum").sum("mioLogList.amnt").as("sumAmnt") // 分组
);
AggregationResults<Object> aggRes = mongoTemplate.aggregate(sumJeAgg, "需要查询的文档",Object.class);
BasicDBList jeBas =(BasicDBList) aggRes.getRawResults().get("result");
BasicDBObject jeDb=(BasicDBObject) jeBas.get(0);
System.out.println(jeDb.get("sumAmnt"));
今天碰到问题,当我:
,写个日志记录下,以免以后继续犯错,知道当加上project后,就不能在group里面自定义key 原因的同学,可以分享下原因吗?