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

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.0.0-rc0
    • Component/s: None
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Execution Team 2021-05-03

      Description

      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"

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: