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

E11000 (duplicate key error) should return a list of duplicate keys and _ids in insert, bulk insert, and continue_on_error inserts.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major - P3
    • Resolution: Unresolved
    • 2.0.2
    • None
    • Index Maintenance
    • None

    Description

      The current output is like this:

      {"err"=>"E11000 duplicate key error index: ruby-test-db.test.$foo_1 dup key: { : 3 }", "code": 11000, "n": 0, "connectionId": 58, "ok": 1.0}

      Three problems:
      1. The duplicate key is specified as part of a string.
      2. Only the latest duplicate key is given. On a bulk insert with continue_on_error, we should get a list containing all duplicate keys found.
      3. If we're given only the duplicate keys, it's hard to be sure which documents were inserted. For that, we also need the _ids of the documents that were rejected.

      Here's the ideal output:

      {"err"=>"E11000 duplicate key error index: ruby-test-db.test.$foo_1 dup keys: [3, 4]",
      "keys": [3, 4], rejected_ids: [ObjectId("4f071fbe935f46ab13686625"), ObjectId("4f071fbe935f46ab13686627")],
      "code": 11000, "n": 0, "connectionId": 58, "ok": 1.0
      }

      Attachments

        Issue Links

          Activity

            People

              michael.gargiulo@mongodb.com Michael Gargiulo
              kbanker Kyle Banker
              Votes:
              24 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

                Created:
                Updated: