Spring Data MongoDB-聚合框架-组操作中的无效引用 [英] Spring Data MongoDB - Aggregation Framework - invalid reference in group Operation

查看:1132
本文介绍了Spring Data MongoDB-聚合框架-组操作中的无效引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring Data(1.3.0.RC1)访问我们的MongoDB,对于某些新查询,我想使用聚合框架.

I use Spring Data (1.3.0.RC1) to access our MongoDB and for some new queries I want to use the aggregation framework.

在mongo shell中,命令为:

In the mongo shell the command would be:

db.spotreports.aggregate(
 { "$unwind" : "$pd"} , { "$group" : { "_id" : "$pd.PDch", "base" : {$sum : "$pd.aBL"}, "uplift" : {$sum : "$pd.up"}}})
{
"result" : [
{
"_id" : 5,
"base" : 529133,
"uplift" : 21516
},
...

我使用的Spring代码是:

The Spring Code I use is:

Aggregation agg = Aggregation.newAggregation(
Aggregation.unwind("pd"),
Aggregation.group("pd.PDch").sum("pd.aBL").as("base").sum("pd.up").as("uplift")
);

AggregationResults<SpotReportResult> result = mongoTemplate.aggregate(agg, resolveCollection(), SpotReportResult.class);

我收到以下错误:

java.lang.IllegalArgumentException: Invalid reference 'PDch'!
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:63)
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:47)
at org.springframework.data.mongodb.core.aggregation.GroupOperation.toDBObject(GroupOperation.java:284)
at org.springframework.data.mongodb.core.aggregation.Aggregation.toDbObject(Aggregation.java:228)

我想知道为什么spring要引用'PDch'而不是'pd.PDch'?

I wonder why spring want to reference 'PDch' instead of 'pd.PDch'?

推荐答案

根据 DATAMONGO-753 应该在最新的快照中修复此问题,并与即将发布的1.3.2错误修正版本和即将发布的Spring Data MongoDB 1.4 M1一起发布.

According to DATAMONGO-753 This should be fixed in the latest snapshots and released with the upcoming 1.3.2 bugfix release and the upcoming 1.4 M1 of Spring Data MongoDB.

这篇关于Spring Data MongoDB-聚合框架-组操作中的无效引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆