collection.ensureIndex should ignore unsupported options

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Index Maintenance
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Running MongoDB 2.6.8, I get:

      > db.notification.getIndexes()[1]
      {
      	"v" : 1,
      	"key" : {
      		"_cls" : 1,
      		"membership" : 1
      	},
      	"ns" : "closeio.notification",
      	"name" : "_cls_1_membership_1",
      	"background" : false,
      	"dropDups" : false
      }
      > db.notification.ensureIndex({ _cls: 1, membership: 1 })
      { "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
      > db.notification.ensureIndex({ _cls: 1, membership: 1 }, { background: true })
      { "numIndexesBefore" : 14, "note" : "all indexes already exist", "ok" : 1 }
      > db.notification.ensureIndex({ _cls: 1, membership: 1 }, { whatever: true })
      {
      	"ok" : 0,
      	"errmsg" : "Index with name: _cls_1_membership_1 already exists with different options",
      	"code" : 85
      }
      > db.notification.ensureIndex({ _cls: 1, membership: 1, whatever:1 }, { whatever: true })
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 14,
      	"numIndexesAfter" : 15,
      	"ok" : 1
      }
      > db.notification.getIndexes()[14]
      {
      	"v" : 1,
      	"key" : {
      		"_cls" : 1,
      		"membership" : 1,
      		"whatever" : 1
      	},
      	"name" : "_cls_1_membership_1_whatever_1",
      	"ns" : "closeio.notification",
      	"whatever" : true
      }
      

      1. Calling ensureIndex with an unsupported option shouldn't consider the spec different from the existing one (i.e. the error shouldn't occur).
      2. Options that aren't supported shouldn't be stored on the index spec.

      Do you agree?

            Assignee:
            Unassigned
            Reporter:
            Stefan Wójcik
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: