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

Enhance error messaging when index creation results in an existing index having the same name

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • Execution Team 2021-05-03

      For convenience, the helper method to create an index does not require that a user specify a name for the index. If a name is unspecified, one is generated in the driver by concatenating the names of the indexed fields and the sort order, e.g. an index on

      {"a": 1}

      will get a default name "a_1".

      The shell method db.collection.createIndex appears to have identical behavior from my testing.

      This can present problems in cases where a user creates multiple indexes in a collection with the same key pattern, as the generated names clash. A user who does something like:

      db.foo.createIndex({a: 1})
      db.foo.createIndex({a: 1}, {collation: 'de'}) 
      

      Will get an error back saying "An existing index has the same name as the requested index". This is confusing as the user never specified a name for either index.

      We should enhance the error messaging when "An existing index has the same name as the requested index" error is generated to ensure users will better diagnose and triage the problem. Perhaps we can consider something like: "when index names are not specified they are auto generated and can cause conflicts please refer to our documentation"

            Assignee:
            yuhong.zhang@mongodb.com Yuhong Zhang
            Reporter:
            michael.gargiulo@mongodb.com Michael Gargiulo
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: