从 Spring Data ReactiveMongoRepository 使用 Collat​​ion 的聪明方法

Smart way to use Collation from Spring Data ReactiveMongoRepository

我们正在 Spring 5 Reactive Stack 上开发应用程序。为了持久化,我们使用来自 Spring 数据的 MongoDb 和 ReactiveMongoRepository (ReactiveCrudRepository)。

目前我们正在使用类似

的查询来获取数据
@Query("{ 'ownerId': ?0, filePath: {$regex: ?1}, tags: { $all : ?2}}")
Flux<Media> findAllByOwnerIdAndFilePathRegexAndTagsContainingAll(String ownerId, String pathRegex, List<Tag> tags);

现在我们要通过区分大小写的标签获取数据。为此,我在数据库中创建了一个索引,其排序规则类似于 { locale: 'en', strength: 2 },如 here 所述。

现在我想使用索引从数据库中获取我的数据。 MonogoDB 的方式是 db.media.find( { filePath: "/example/" } ).collation( { locale: 'en', strength: 2 } )

有人知道使用 ReactiveMongoRepository 中的排序规则的巧妙方法吗?

使用当前版本的 Spring 数据,您需要使用 MongoOperations 提供定义 Collation.
Query 详情请参考Reference Documentation

请确保同时检查 DATAMONGO-1854 上的 out/comment,它建议将 collat​​ion 添加到 @Query