【问题标题】:MongoDB - Can I use @TextIndexed and @Indexed on a field at the same time?MongoDB - 我可以同时在一个字段上使用@TextIndexed 和@Indexed 吗?
【发布时间】:2020-02-19 09:50:05
【问题描述】:

MongoDB中的同一列是否可以同时拥有索引和文本索引?

我想按国家代码(即“美国”)查询Question 集合,并以国家代码作为id 展开Country 集合中的相关数据。

Spring Data MongoDB / Kotlin 的示例代码:

@Document
data class Question(
    @Id val id: String,

    @TextIndexed
    @Indexed(name = "question_country_code_index")
    val countryCode: String
)

【问题讨论】:

    标签: mongodb kotlin spring-data-mongodb mongodb-indexes


    【解决方案1】:

    可以将两个注解应用于同一个属性。然后IndexResolver 将创建两个索引。

    {
        "v" : 2,
        "key" : {
            "_fts" : "text",
            "_ftsx" : 1
        },
        "name" : "Question_TextIndex",
        "ns" : "db.question",
        "weights" : {
            "textIndexedPropertyWithDefaultWeight" : 1
        },
        "language_override" : "language",
        "textIndexVersion" : 3
    },
    {
        "v" : 2,
        "key" : {
            "countryCode" : 1
        },
        "name" : "question_country_code_index",
        "ns" : "db.question",
        "collation" : {
            ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-08
      • 2013-02-19
      • 2021-09-10
      • 1970-01-01
      • 2012-03-13
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多