Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31089

createIndex fails with "Index type 'text' does not support collation" but applyops command succeeds for creating the same index

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Hide

      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 }
      
      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 }

      If a collection is created with collation specification, creation of a text index fails if {collation.locale: "simple"} is not provided during index creation. Creating the same index using applyOps command succeeds even if the {collation.locale: "simple"} is not provided in the applyops command.
      This behaviour is breaking backup initial sync, because during initial sync it creates index using createIndex command. Backup does not know about the collation, because 'db.collection.geIndexes' and oplog for index creation does not have collation info.

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            ankur.srivastava@mongodb.com Ankur Srivastava (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: