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

Upsert errors with "duplicate key error"

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.5
    • Component/s: Storage
    • None
    • ALL
    • Hide
      load('jstests/libs/parallelTester.js'); // for ScopedThread
      
      var t = db.getSiblingDB("upsert_bug").getCollection("col");
      
      t.drop();
      
      var upsertFn = function() {
        for (var i = 0; i < 100; ++i) {
          var c = db.getSiblingDB("upsert_bug").getCollection("col");
          var x = c.update({_id:3}, {$set: {a:'123', b: Math.random()}}, true)
          assert(!x.getWriteError(), tojson(x));
          c.remove({"_id":3});
        }
      }
      
      var threads = [];
      for (var i = 0; i < 2; ++i) {
        var thread = new ScopedThread(upsertFn, db);
        threads.push(thread);
        thread.start();
      }
      
      threads.forEach(function(t) {
          t.join();
      });
      

      Result:

      ./mongo < ~/tmp/upsert_bug.js
      MongoDB shell version: 3.0.5
      connecting to: test
      true
      true
      connecting to: test
      connecting to: test
      assert failed : {
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 11000,
                      "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
              }
      }
      Error: assert failed : {
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 11000,
                      "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
              }
      }
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at assert (src/mongo/shell/assert.js:20:5)
          at ____MongoToV8_newFunction_temp (<anonymous>:5:5)
      2015-08-18T16:34:39.075-0700 I -        js thread raised js exception: Error: assert failed : {
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 11000,
                      "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }"
              }
      }
          at Error (<anonymous>)
          at doassert (src/mongo/shell/assert.js:11:14)
          at assert (src/mongo/shell/assert.js:20:5)
          at ____MongoToV8_newFunction_temp (<anonymous>:5:5) at src/mongo/shell/assert.js:13
      bye
      
      
      
      Show
      load('jstests/libs/parallelTester.js'); // for ScopedThread var t = db.getSiblingDB("upsert_bug").getCollection("col"); t.drop(); var upsertFn = function() { for (var i = 0; i < 100; ++i) { var c = db.getSiblingDB("upsert_bug").getCollection("col"); var x = c.update({_id:3}, {$set: {a:'123', b: Math.random()}}, true) assert(!x.getWriteError(), tojson(x)); c.remove({"_id":3}); } } var threads = []; for (var i = 0; i < 2; ++i) { var thread = new ScopedThread(upsertFn, db); threads.push(thread); thread.start(); } threads.forEach(function(t) { t.join(); }); Result: ./mongo < ~/tmp/upsert_bug.js MongoDB shell version: 3.0.5 connecting to: test true true connecting to: test connecting to: test assert failed : { "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }" } } Error: assert failed : { "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }" } } at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at ____MongoToV8_newFunction_temp (<anonymous>:5:5) 2015-08-18T16:34:39.075-0700 I - js thread raised js exception: Error: assert failed : { "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: upsert_bug.col index: _id_ dup key: { : 3.0 }" } } at Error (<anonymous>) at doassert (src/mongo/shell/assert.js:11:14) at assert (src/mongo/shell/assert.js:20:5) at ____MongoToV8_newFunction_temp (<anonymous>:5:5) at src/mongo/shell/assert.js:13 bye

      Hello there.

      We're seeing an upsert command erroring with "duplicate key error". We managed to get a consistent reproduction and it reproduces for both WiredTiger and RocksDB storage engines.

            Assignee:
            Unassigned Unassigned
            Reporter:
            igor Igor Canadi
            Votes:
            1 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: