如何在Spring数据mongo查询中使用聚合和动态排序

时间:2020-03-05 08:49:43

标签: spring mongodb spring-data-mongodb

我正在尝试在自定义的Spring存储库上使用Spring实现mongoTemplate聚合,并且我有这样的聚合:

final TypedAggregation aggregation = newAggregation(Result.class,
            lookupOperation,
            addFieldOperation,
            unWindOperation,
            groupOperation,
    ), "inputCollection", Result.class).getMappedResults();

我想添加Spring SortOperation sort()并仅在条件有效时进行过滤。 有什么方法可以将AggregationOperation添加到aggregation变量中?

我发现AggregationOptions cursor将其他选项传递给聚合,但是找不到如何实例化排序的方法。有机会帮助我做到这一点吗?

0 个答案:

没有答案