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

duplicate key error should report field names as well as values

    XMLWordPrintableJSON

Details

    • Fully Compatible
    • Storage NYC 2018-09-24

    Description

      Consider a compound index with a name:

      db.test.ensureIndex( { a: 1, b : 1 }, { unique: true, name : 'index_1' }

      A duplicate key error on that index reports this errmsg:

      "errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: admin.test.$index_1  dup key: { : 1.0, : 2.0 }"

      The dup key is a string that looks like JSON but is missing the field names. It would be easier for clients to understand the error message if the dup key contained the field names as well as the values, especially in the case of named indexes where the index name doesn't provide enough of a clue, e.g.

      "errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: admin.test.$index_1  dup key: { a : 1.0, b : 2.0 }"

      I'd also prefer that the index name be rendered without the collection name or the $. Clients know what collection they are using. and the $ is not part of the index name from the clients perspective.

      Attachments

        Issue Links

          Activity

            People

              xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
              jeff.yemin@mongodb.com Jeffrey Yemin
              Votes:
              2 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: