MongoDB - 我可以同时在一个字段上使用@TextIndexed 和@Indexed 吗?

MongoDB - Can I use @TextIndexed and @Indexed on a field at the same time?

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

我想查询 Question 按国家代码收集(即 "US")并展开 Country 按国家代码收集的相关数据作为 id。

Spring 数据 MongoDB/Kotlin 的示例代码:

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

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

可以将两个注释应用到同一个 属性。 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" : {
        ...
    }
}