java - 如何在spring boot mongoDB中进行聚合和排序?
问题描述
我有以下模型结构:
@Getter
@Setter
@Document(collection = "tbl_user")
public class UsersInfo extends BaseModel {
public UserContentInfo userContentInfoList;
}
public class UserContentInfo
{
private List<VideoInfo> videoPost;
private List<VideoInfo> highlightVideos;
private List<ImageInfo> imageInfoList;
}
而VideoInfo
:
public class VideoInfo
{
private String videoUrl;
private Long addedAt;
}
我正在尝试基于sorting
.
Aggregation aggregation = Aggregation.newAggregation(Aggregation.match(Criteria.where(Constant.COMMON_ID).is(userId)), Aggregation.sort(Sort.Direction.DESC, "userContentInfoList.videoPost.addedAt").and(Sort.Direction.DESC,
"userContentInfoList.highlightVideos.addedAt")
);
return mongoOperations.aggregate(aggregation, UsersInfo.class, UsersInfo.class);
但这给我带来了以下错误:
Command failed with error 2 (BadValue): 'PlanExecutor error during aggregation :: caused by :: cannot sort with keys that are parallel arrays' on server
我在这里做错了什么?
解决方案
推荐阅读
- java - Java File Downloader
- slack - Slack API slash commands and interactive components modal
- python - Python如何将自定义函数导入另一个脚本(任务计划程序中的问题)
- machine-learning - 连续变量的贝叶斯网络结构学习python包
- mobx-state-tree - mobx-state-tree 是否支持嵌套模型?
- php - 解码json值后如何显示该值?
- laravel - Laravel 中的搜索有很多关系
- pandas - 两个数据帧的完全外连接
- javascript - 选择 HTML 的选项自动化
- python - 在 csv 文件中查找数字的最接近价格