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

createIndex on existing index but different name should return error

    • Query
    • ALL

      For the most part, ensureIndex on an existing index but with different options error, but if the only difference is the name, it doesn't error.

      > db.test.ensureIndex( { foo: 1 } )
      WriteResult({ "nInserted" : 1 })
      > db.test.ensureIndex( { foo: 1 }, { unique: true } )
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 67,
      		"errmsg" : "Index with name: foo_1 already exists with different options"
      	}
      })
      > db.test.ensureIndex( { foo: 1 }, { name: "kay"} )
      WriteResult({ "nInserted" : 0 })
      > db.test.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "test.test"
      	},
      	{
      		"v" : 1,
      		"key" : {
      			"foo" : 1
      		},
      		"name" : "foo_1",
      		"ns" : "test.test"
      	}
      ]
      

      Given that the check seems to be by name, I can see that if the names differ, then of course, it won't do the check but wasn't sure.

      If this is the expected behavior, I can just simply state that if an index already exists with the same name, ensureIndex will error if the key specs or the options differ. instead of having two separate error cases of (same key spec, different options) = error and (different key spec, same name) = error

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: