[SERVER-13290] createIndex on existing index but different name should return error Created: 19/Mar/14  Updated: 06/Dec/22  Resolved: 05/Jul/19

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.6.0-rc1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kay Kim (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-33149 createIndexes fails to report an erro... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by David Storch [ 05/Jul/19 ]

It looks like this has been fixed under SERVER-33149. Resolving as a duplicate.

Comment by Valery Khamenya [ 18/Feb/16 ]

this restriction prohibits creation of ver1 indices without dropping ver0

Comment by J Rassi [ 26/Mar/14 ]

Re-opening, this didn't go away in rc2; I think you two are confused.

rassi@laptop:~/work/mongo $ mongo260rc2
MongoDB shell version: 2.6.0-rc2
connecting to: test
> db.version()
2.6.0-rc2
> db.foo.drop()
false
> db.foo.insert({foo:1})
WriteResult({ "nInserted" : 1 })
> db.foo.ensureIndex({foo:1})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.ensureIndex({foo:1},{name:"kay"})
{ "numIndexesBefore" : 2, "note" : "all indexes already exist", "ok" : 1 }
> db.foo.ensureIndex({foo:1},{unique:true})
{
	"ok" : 0,
	"errmsg" : "Index with name: foo_1 already exists with different options",
	"code" : 67
}
>

The issue Kay is reporting here is that db.foo.ensureIndex({foo:1},{name:"kay"}) should return an error, since an index with name "kay" can't be created due to a key pattern conflict with an existing index.

Comment by Kay Kim (Inactive) [ 25/Mar/14 ]

dan@10gen.com seems to be fixed in rc2.

Comment by Daniel Pasette (Inactive) [ 25/Mar/14 ]

I can't repro with 2.6.0-rc2. kay.kim@10gen.com, can you check again?

Generated at Thu Feb 08 03:31:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.