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

Use of codeName should be consistent across error messages

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Query Optimization

      Say we have two documents with two fields in a collection (testing), with a compound unique index:

      use test
      db.testing.insert({ a: 1, b: 1 })
      db.testing.insert({ a: 1, b: 2 })
      db.testing.createIndex({ a: 1, b: 1 }, { unique: true })
      

      The error message generated by a call to findAndModify that violates the unique index is as follows:

      test> db.testing.findAndModify({ query: { a: 1,b: 1 }, update: { a: 1,b: 2 } })
      2018-03-12T21:46:46.427-0400 E QUERY    [thread1] Error: findAndModifyFailed failed: {
        "operationTime": Timestamp(1520905600, 1),
        "ok": 0,
        "errmsg": "E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 2.0 }",
        "code": 11000,
        "codeName": "DuplicateKey",
        "$clusterTime": {
          "clusterTime": Timestamp(1520905600, 1),
          "signature": {
            "hash": BinData(0, "eiANq76RZ704EWnDJSY3orlIWxM="),
            "keyId": NumberLong("6532150305184808961")
          }
        }
      } :
      _getErrorWithCode@src/mongo/shell/utils.js:25:13
      DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:724:1
      @(shell):1:1
      

      In the above error message, codeName is specified. However in an insert or update operation, the codeName field is not specified:

      test> db.testing.insert({a:1,b:1})
      E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 1.0 }
      WriteResult({
        "nInserted": 0,
        "writeError": {
          "code": 11000,
          "errmsg": "E11000 duplicate key error collection: test.testing index: a_1_b_1 dup key: { : 1.0, : 1.0 }"
        }
      })
      

      These error messages should be made consistent across all methods in the shell.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            julian.torres@mongodb.com Julian Torres
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: