簡體   English   中英

CompoundIndex spring 不區分大小寫

[英]CompoundIndex spring case insensitive

所以,我正在從 Spring 級別處理 MongoDB 中的索引。 我想使用不區分大小寫的索引。

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

從上面的 mongo 文檔中我可以看到,從 DB 級別可以通過使用強度整理來完成,並且應該在 createIndex 函數中使用。 但是我找不到有關如何使用 CompoundIndex 注釋中的選項的任何信息。

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

在 Spring 文檔中,沒有關於選項的消息。 任何人都知道如何做到這一點?

我沒有在@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()))
        )
    }

我一直在尋找相同的信息,發現你可以使用這個:

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

文檔中沒有提到它,但我發現了一個懸而未決的問題( https://jira.spring.io/browse/DATAMONGO-2133

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM