简体   繁体   English

CompoundIndex spring 不区分大小写

[英]CompoundIndex spring case insensitive

So, I am working on indexes in MongoDB from Spring level.所以,我正在从 Spring 级别处理 MongoDB 中的索引。 I want to use the case insensitive index.我想使用不区分大小写的索引。

https://docs.mongodb.com/v3.4/core/index-case-insensitive/ https://docs.mongodb.com/v3.4/core/index-case-insensitive/

From above mongo documentation I can see that from DB level it can be done by using the strength collation and should be used in createIndex function.从上面的 mongo 文档中我可以看到,从 DB 级别可以通过使用强度整理来完成,并且应该在 createIndex 函数中使用。 But I was unable to find any information about how to use the options in the CompoundIndex annotation.但是我找不到有关如何使用 CompoundIndex 注释中的选项的任何信息。

http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/index/CompoundIndex.html http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/index/CompoundIndex.html

On Spring dosc there is no word about options.在 Spring 文档中,没有关于选项的消息。 Anyone has a clue how to do it?任何人都知道如何做到这一点?

I didn't find such an option in annotations like @Indexed, but you can use something like this to ensure index exists with collation:我没有在@Indexed 之类的注释中找到这样的选项,但是您可以使用类似的方法来确保索引存在与排序规则:

@Configuration
@DependsOn("mongoTemplate")
class CollectionConfig(@Autowired private val mongoTemplate: MongoTemplate) {

    @PostConstruct
    fun ensureIndexes() {
        mongoTemplate.indexOps(DbObject::class.java).ensureIndex(
                Index("fieldName", Sort.Direction.ASC)
                        .unique()
                        .background()
                     .collation(of(Locale.ENGLISH).strength(ComparisonLevel.secondary()))
        )
    }

I was looking for the same information and found out that you can use this:我一直在寻找相同的信息,发现你可以使用这个:

@CompoundIndex(name = "name_field", def = "{field1: 1,field2:1}{collation:'en', strength:2}")

it's not mentioned in the documentation but I found an open issue about that ( https://jira.spring.io/browse/DATAMONGO-2133 )文档中没有提到它,但我发现了一个悬而未决的问题( https://jira.spring.io/browse/DATAMONGO-2133

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM