是否可以在MongoDB的同一列上同时具有索引和文本索引?
我想按国家/地区代码(即“美国”)查询Question
集合,并按国家/地区代码将Country
集合中的相关数据展开为ID。
Spring Data 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" : {
...
}
}