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

The dropDups index option should be ignored if the index already exists

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.6.0-rc2
    • Affects Version/s: None
    • Component/s: Index Maintenance
    • None
    • ALL

      If you create an index with dropDups:true then you cannot call ensureIndex again without the dropDups:true. The background:T/F option is already ignored .

      Both dropDups and background only influence MongoDB behavior when creating the index. Therefore, it seems like neither of them should be considered part of the index definition wrt if the index already exists, and should not be used to compare for an existing index.

      dropDups behavior

      backup_test:PRIMARY> db.users.ensureIndex({username:1},{name:'idxUsername',unique:true,dropDups:true})
      WriteResult({ "nInserted" : 1 })
      backup_test:PRIMARY> db.users.ensureIndex({username:1},{name:'idxUsername',unique:true})
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 67,
      		"errmsg" : "Index with name: idxUsername already exists with different options"
      	}
      })
      

      background behavior

      backup_test:PRIMARY> db.users.ensureIndex({username:1},{unique:true, name: 'idxUsername', background:true})
      WriteResult({ "nInserted" : 1 })
      backup_test:PRIMARY> db.users.ensureIndex({username:1},{unique:true, name: 'idxUsername'})
      WriteResult({ "nInserted" : 0 })
      

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            cailin.nelson@mongodb.com Cailin Nelson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: