暂无图片
mongodbtemplate 关联表查询报错
我来答
分享
暂无图片 匿名用户
mongodbtemplate 关联表查询报错

我有两个表:url和userClickUrl表,字段如下
url:

String id;
String uid;
String title;

```userClickUrl:
String id;
// 跟url中的id关联
String urlId;
String uid;
int clickCount
现在我想使用userClickUrl为主表,url为子表,根据clickCount排序,查询url数据,但是报错,下面是java代码:

LookupOperation lookupOperation = Aggregation.lookup(“url”, “urlId”, “_id”, “url_as”);
AggregationOperation match = Aggregation.match(Criteria.where(“uid”).is(uid));
ProjectionOperation project = Aggregation.project(UserClickUrl.class);
SortOperation sort = Aggregation.sort(Sort.Direction.DESC, “clickCount”);
LimitOperation limit = Aggregation.limit(10);
operationList.add(lookupOperation);
operationList.add(match);
operationList.add(addFieldsOperation);
operationList.add(project);
operationList.add(sort);
operationList.add(limit);
Aggregation agg = Aggregation.newAggregation(operationList);
AggregationResults aggregationResults = mongoTemplate.aggregate(agg, “userClickUrl”, UserClickUrl.class);
List dataList = aggregationResults.getMappedResults();

2021-09-22 09:50:26.182 ERROR 2119 — [nio-8902-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Invalid reference ‘clickCount’!] with root cause

java.lang.IllegalArgumentException: Invalid reference ‘clickCount’!
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:114) ~[spring-data-mongodb-3.1.3.jar:3.1.3]
at org.springframework.data.mongodb.core.aggregation.ExposedFieldsAggregationOperationContext.getReference(ExposedFieldsAggregationOperationContext.java:86) ~[spring-data-mongodb-3.1.3.jar:3.1.3]


我来答
添加附件
收藏
分享
问题补充
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏