gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:53:43 25 4
gpt4 key购买 nike

我们正在 Spring 5 Reactive Stack 上开发一个应用程序。为了持久化,我们将 MongoDb 与来自 Spring Data 的 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/"} ).collat​​ion( { locale: 'en', strength: 2 } )

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

最佳答案

对于当前版本的 Spring Data,您需要使用 MongoOperations 提供定义 Collat​​ionQuery
请引用Reference Documentation有关详细信息。

请确保也查看/评论 DATAMONGO-1854它建议将 collat​​ion 添加到 @Query

关于spring - 从 Spring Data ReactiveMongoRepository 使用 Collat​​ion 的聪明方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53787378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com