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

createIndexes fails to report an error when index is not created with the specified name

    • Fully Compatible
    • ALL
    • Hide

      Setup:

      > use test
      switched to db test
      > db.test.drop()
      true
      > db.runCommand({ createIndexes: "test", indexes : [ { key : { x : 1 }, name : "x_1" } ] })
      {
              "createdCollectionAutomatically" : true,
              "numIndexesBefore" : 1,
              "numIndexesAfter" : 2,
              "ok" : 1
      }
      

      Reproduction (note that name is different from above):

      > db.runCommand({ createIndexes: "test", indexes : [ { key : { x : 1 }, name : "x_2" } ] })
      {
              "createdCollectionAutomatically" : false,
              "numIndexesBefore" : 2,
              "numIndexesAfter" : 2,
              "note" : "all indexes already exist",
              "ok" : 1
      }
      >
      

      The problem: since the server returned { ok : 1 } that implies that an index with the name "x_2" must exist.

      But that is not true.

      Expected result:

      Some sort of error message indicating that the second index was NOT created. Perhaps similar to the error message when trying to create a second index with conflicting options:

      > db.runCommand({ createIndexes: "test", indexes : [ { key : { x : 1 }, name : "x_1", unique : true } ] })
      {
              "ok" : 0,
              "errmsg" : "Index with name: x_1 already exists with different options",
              "code" : 85,
              "codeName" : "IndexOptionsConflict"
      }
      >
      

      Suggested errmsg: Index with the same keys but a different name already exists.

      Show
      Setup: > use test switched to db test > db.test.drop() true > db.runCommand({ createIndexes: "test" , indexes : [ { key : { x : 1 }, name : "x_1" } ] }) { "createdCollectionAutomatically" : true , "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } Reproduction (note that name is different from above): > db.runCommand({ createIndexes: "test" , indexes : [ { key : { x : 1 }, name : "x_2" } ] }) { "createdCollectionAutomatically" : false , "numIndexesBefore" : 2, "numIndexesAfter" : 2, "note" : "all indexes already exist" , "ok" : 1 } > The problem: since the server returned { ok : 1 } that implies that an index with the name "x_2" must exist. But that is not true. Expected result: Some sort of error message indicating that the second index was NOT created. Perhaps similar to the error message when trying to create a second index with conflicting options: > db.runCommand({ createIndexes: "test" , indexes : [ { key : { x : 1 }, name : "x_1" , unique : true } ] }) { "ok" : 0, "errmsg" : "Index with name: x_1 already exists with different options" , "code" : 85, "codeName" : "IndexOptionsConflict" } > Suggested errmsg: Index with the same keys but a different name already exists.
    • Storage NYC 2019-03-11, Storage NYC 2019-03-25
    • 3

      The createIndexes command fails to report an error when an index is not created with the specified name because an index already exists with the same keys but with a different name.

            Assignee:
            gregory.wlodarek@mongodb.com Gregory Wlodarek
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            1 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved: