【发布时间】:2013-01-13 10:24:30
【问题描述】:
我有一个包含字段id, a-int, b-int, c-int, total-int 的集合。我试图得到a, b, c, total,但我最终得到的只是total 的总和,其余字段值为0, 0, 0。我该如何解决?以下数据样本的预期结果10, 20, 30, 300
谢谢
数据样本
id, a, b, c, total
xid, 10, 20, 30, 100
xid, 10, 20, 30, 200
GroupBy groupBy = GroupBy.key("{a : 1, b : 1, c : 1}")
.initialDocument("{ total: 0 }")
.reduceFunction("function(obj, result) { result.total += obj.total; }");
GroupByResults<Grouped> results = mongoTemplate.group(Criteria.where("id").is(id),
TABLE, groupBy, Grouped.class);
【问题讨论】:
标签: spring mongodb spring-mvc