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

shell does not report a duplicate key error when creating a unique index fails

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • None
    • ALL
    • Hide
      $ cat tmp/foo.js
      db.foo.drop();
      db.foo.insert({ foo: 'bar' });
      db.foo.insert({ foo: 'bar' });
      db.foo.createIndex({ foo: 1 }, { unique: true });
      db.foo.getIndexes();
      
      $ mongo tmp/foo.js
      MongoDB shell version: 3.2.18
      connecting to: test
      
      $ echo $?
      0
      
      $ mongo < tmp/foo.js
      MongoDB shell version: 3.2.18
      connecting to: test
      true
      WriteResult({ "nInserted" : 1 })
      WriteResult({ "nInserted" : 1 })
      {
      	"ok" : 0,
      	"errmsg" : "E11000 duplicate key error index: test.foo.$foo_1 dup key: { : \"bar\" }",
      	"code" : 11000
      }
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "test.foo"
      	}
      ]
      bye
      
      $ echo $?
      0
      
      Show
      $ cat tmp/foo.js db.foo.drop(); db.foo.insert({ foo: 'bar' }); db.foo.insert({ foo: 'bar' }); db.foo.createIndex({ foo: 1 }, { unique: true }); db.foo.getIndexes(); $ mongo tmp/foo.js MongoDB shell version: 3.2.18 connecting to: test $ echo $? 0 $ mongo < tmp/foo.js MongoDB shell version: 3.2.18 connecting to: test true WriteResult({ "nInserted" : 1 }) WriteResult({ "nInserted" : 1 }) { "ok" : 0, "errmsg" : "E11000 duplicate key error index: test.foo.$foo_1 dup key: { : \"bar\" }", "code" : 11000 } [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } ] bye $ echo $? 0

      running a scripted set of commands from the shell with `mongo tmp/foo.js` does not report errors

            Assignee:
            mira.carey@mongodb.com Mira Carey
            Reporter:
            derek@echologic.com Derek Scherger
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: