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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.6.2
    • Fix Version/s: 4.1.10
    • Component/s: Indexing
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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.
    • Sprint:
      Storage NYC 2019-03-11, Storage NYC 2019-03-25
    • Story Points:
      3

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                18 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: