Unique Index Creation Fails Despite `dropDups`

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.0.0, 3.0.1
    • Component/s: Index Maintenance
    • None
    • ALL
      1. Open MongoDB Shell
      2. Switch to database `mydb`
      3. Insert `{x: 1}` into collection `testData`
      4. Create index on key `x` of collection `testData`, specifying option `{unique: true, dropDups: true}`
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When attempting to create a unique index on a key with duplicates (i.e. using the `dropDups: true` option), the index creation fails with a duplicate key error.

      MongoDB shell version: 3.0.1
      connecting to: test
      > use mydb
      switched to db mydb
      > db.testData.insert({x: 1})
      WriteResult({ "nInserted" : 1 })
      > db.testData.insert({x: 1})
      WriteResult({ "nInserted" : 1 })
      > db.testData.createIndex({x: 1}, {unique: true, dropDups: true})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 1,
      	"errmsg" : "exception: E11000 duplicate key error index: mydb.testData.$x_1 dup key: { : 1.0 }",
      	"code" : 11000,
      	"ok" : 0
      }
      

              Assignee:
              Unassigned
              Reporter:
              Christian Bankester
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: