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

Index created through applyOps command should not inherit collection default collation

    • Fully Compatible
    • ALL
    • v3.4
    • Hide
      > db.createCollection("c", {collation: {locale: "en_US"}})
      { "ok" : 1, "operationTime" : Timestamp(1505846099, 1) }
      > db.runCommand({applyOps: [{ "ts" : Timestamp(1505846037, 1), "t" : NumberLong(1), "h" : NumberLong("216366330843306159"), "v" : 2, "op" : "i", "ns" : "test.system.indexes", "o" : { "v" : 2, "key" : { "a" : 1 }, "name" : "a_1", "ns" : "test.c" } }]})
      {
      	"applied" : 1,
      	"results" : [
      		true
      	],
      	"ok" : 1,
      	"operationTime" : Timestamp(1505846128, 1)
      }
      > db.c.getIndexes()
      [
      	{
      		"v" : 2,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "test.c",
      		"collation" : {
      			"locale" : "en_US",
      			"caseLevel" : false,
      			"caseFirst" : "off",
      			"strength" : 3,
      			"numericOrdering" : false,
      			"alternate" : "non-ignorable",
      			"maxVariable" : "punct",
      			"normalization" : false,
      			"backwards" : false,
      			"version" : "57.1"
      		}
      	},
      	{
      		"v" : 2,
      		"key" : {
      			"a" : 1
      		},
      		"name" : "a_1",
      		"ns" : "test.c",
      		"collation" : {
      			"locale" : "en_US",
      			"caseLevel" : false,
      			"caseFirst" : "off",
      			"strength" : 3,
      			"numericOrdering" : false,
      			"alternate" : "non-ignorable",
      			"maxVariable" : "punct",
      			"normalization" : false,
      			"backwards" : false,
      			"version" : "57.1"
      		}
      	}
      ]
      
      Show
      > db.createCollection( "c" , {collation: {locale: "en_US" }}) { "ok" : 1, "operationTime" : Timestamp(1505846099, 1) } > db.runCommand({applyOps: [{ "ts" : Timestamp(1505846037, 1), "t" : NumberLong(1), "h" : NumberLong( "216366330843306159" ), "v" : 2, "op" : "i" , "ns" : "test.system.indexes" , "o" : { "v" : 2, "key" : { "a" : 1 }, "name" : "a_1" , "ns" : "test.c" } }]}) { "applied" : 1, "results" : [ true ], "ok" : 1, "operationTime" : Timestamp(1505846128, 1) } > db.c.getIndexes() [ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_" , "ns" : "test.c" , "collation" : { "locale" : "en_US" , "caseLevel" : false , "caseFirst" : "off" , "strength" : 3, "numericOrdering" : false , "alternate" : "non-ignorable" , "maxVariable" : "punct" , "normalization" : false , "backwards" : false , "version" : "57.1" } }, { "v" : 2, "key" : { "a" : 1 }, "name" : "a_1" , "ns" : "test.c" , "collation" : { "locale" : "en_US" , "caseLevel" : false , "caseFirst" : "off" , "strength" : 3, "numericOrdering" : false , "alternate" : "non-ignorable" , "maxVariable" : "punct" , "normalization" : false , "backwards" : false , "version" : "57.1" } } ]
    • Query 2017-10-23

      An index created through the applyOps command currently inherits the collection default collation. This behavior is incorrect--replicating such an oplog entry does not cause the index to inherit the collection default collation. This is important, because for indexes with the simple collation, the collation is not specified in the oplog entry, even if the collection has a non-simple default collation.

      Note that this bug only applies to oplog entries phrased as insertions into system.indexes, which are only generated when the featureCompatibilityVersion is 3.4. It does not apply to oplog entries of the form:

      { "ts" : Timestamp(1505845525, 1), "t" : NumberLong(1), "h" : NumberLong("8738799795251471513"), "v" : 2, "op" : "c", "ns" : "test.$cmd", "ui" : UUID("03829ff6-acc7-45a3-ab78-9bf4b563ba9c"), "wall" : ISODate("2017-09-19T18:25:25.757Z"), "o" : { "createIndexes" : "c", "v" : 2, "key" : { "a" : 1 }, "name" : "a_1" } }
      

      Indexes created through the applyOps command using this style of oplog entry correctly do not inherit the collection default collation.

      Note also that this bug does not apply to 3.4--it only exists in master.

      This appears to happen because in the applyOps command, direct inserts into system.indexes cause us to run createIndexes directly on the server. This behavior was introduced in this commit.

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: