【发布时间】:2020-05-14 03:58:06
【问题描述】:
我正在将 Spring Boot Kotlin 与 MongoDB 一起使用。在这个项目中,我有一个类,它有一个名为 pointsEntry 的数组属性。在我自己的 findAll 方法中检索它们时,我一直在尝试使用运算符 $slice 仅获取所有列表的第一个 pointsEntry。在我的 Mongo 客户端中尝试此查询时有效:
db.getCollection('collectionName').find( {}, { "pointsEntry" : { $slice: 1 } } )
但是,我在我的 Spring Boot 项目中使用 @Query 注释尝试了类似的方法,但它总是报错
注解参数必须是编译时常量
@Query(value = "{}",fields = "{pointsEntry: {'$slice' : ?0}}")
fun findAll() : List<DocumentName>
【问题讨论】:
标签: spring mongodb spring-boot kotlin