Show
create a collection:
db.createCollection("customers", {collation: {locale: "en_US", caseLevel: false, caseFirst: "off", strength: 2, numericOrdering: false, alternate: "non-ignorable", maxVariable: "punct", normalization: false, backwards: false}})
Create index with collation
db.customers.createIndex({ "_fts" : "text" , "_ftsx" : 1}, {name: "CustomerText", collation: { locale: "simple"}, "weights" : { "Locations.Address1" : 1 , "Locations.City" : 1 , "Locations.Contacts.FirstName" : 1 , "Locations.Contacts.LastName" : 1 , "Locations.Name" : 1 , "Name" : 1}})
Here is the result of getIndexes and oplog entry. Notice that collation specification is not present here.
db.customers.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "bkp.customers",
"collation" : {
"locale" : "en_US",
"caseLevel" : false,
"caseFirst" : "off",
"strength" : 2,
"numericOrdering" : false,
"alternate" : "non-ignorable",
"maxVariable" : "punct",
"normalization" : false,
"backwards" : false,
"version" : "57.1"
}
},
{
"v" : 2,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "CustomerText",
"ns" : "bkp.customers",
"weights" : {
"Locations.Address1" : 1,
"Locations.City" : 1,
"Locations.Contacts.FirstName" : 1,
"Locations.Contacts.LastName" : 1,
"Locations.Name" : 1,
"Name" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 3
}
]
{ "ts" : Timestamp(1505396756, 1), "t" : NumberLong(1), "h" : NumberLong("3117262685112057819"), "v" : 2, "op" : "i", "ns" : "bkp.system.indexes", "o" : { "v" : 2, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "CustomerText", "ns" : "bkp.customers", "weights" : { "Locations.Address1" : 1, "Locations.City" : 1, "Locations.Contacts.FirstName" : 1, "Locations.Contacts.LastName" : 1, "Locations.Name" : 1, "Name" : 1 }, "default_language" : "english", "language_override" : "language", "textIndexVersion" : 3 } }
try to create index without collation:
db.customers.dropIndex("CustomerText")
db.customers.createIndex({ "_fts" : "text" , "_ftsx" : 1}, {name: "CustomerText", "weights" : { "Locations.Address1" : 1 , "Locations.City" : 1 , "Locations.Contacts.FirstName" : 1 , "Locations.Contacts.LastName" : 1 , "Locations.Name" : 1 , "Name" : 1}})
{
"ok" : 0,
"errmsg" : "Index type 'text' does not support collation: { locale: \"en_US\", caseLevel: false, caseFirst: \"off\", strength: 2, numericOrdering: false, alternate: \"non-ignorable\", maxVariable: \"punct\", normalization: false, backwards: false, version: \"57.1\" }",
"code" : 67,
"codeName" : "CannotCreateIndex"
}
try to create index without collation using applyops:
db.runCommand({applyOps: [{ "ts" : Timestamp(1505396756, 1), "t" : NumberLong(1), "h" : NumberLong("3117262685112057819"), "v" : 2, "op" : "i", "ns" : "bkp.system.indexes", "o" : { "v" : 2, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "CustomerText", "ns" : "bkp.customers", "weights" : { "Locations.Address1" : 1, "Locations.City" : 1, "Locations.Contacts.FirstName" : 1, "Locations.Contacts.LastName" : 1, "Locations.Name" : 1, "Name" : 1 }, "default_language" : "english", "language_override" : "language", "textIndexVersion" : 3 } }]})
{ "applied" : 1, "results" : [ true ], "ok" : 1 }