[SERVER-2618] Attempting to create a new index that already exists with diff option fails silently Created: 24/Feb/11  Updated: 12/Jul/16  Resolved: 17/Jun/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 2.5.1

Type: Bug Priority: Major - P3
Reporter: Antoine Girbal Assignee: Randolph Tan
Resolution: Done Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by SERVER-2699 ensureIndex() fails to create unique ... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

if calling createIndex on already existing index, but with different options (like unique), no error is raised but index is not changed

At the end of following, the index is not unique:

foo:PRIMARY> db.test2.createIndex({c:1})
foo:PRIMARY> db.test2.createIndex({c:1}, {unique: true})
foo:PRIMARY> db.system.indexes.find()
{ "_id" : ObjectId("4d65b40cb91238df65f3e841"), "ns" : "mydb.test2", "key" : { "c" : 1 }, "name" : "c_1", "v" : 0 }



 Comments   
Comment by Alexander Yahnev [X] [ 11/Jan/14 ]

In pymongo 2.6.3 this bug still exists. That's pretty annoying for novice in mongodb, because bug looks like it can be corrected with a simple condition checking.

Comment by Scott Hernandez (Inactive) [ 17/Jun/13 ]

This is backwards breaking because before an error wasn't generated, and now they will be.

Comment by auto [ 17/Jun/13 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-2618 Attempting to create a new index that already exists with diff option fails silently
Branch: master
https://github.com/mongodb/mongo/commit/a2056afecf016c4798cd16f594c719ce6e893196

Comment by John Woakes [ 22/Oct/12 ]

Also happens when you try an create a TTL index on a field that already has an index.

Comment by Tad Marshall [ 14/Oct/12 ]

I think that we should fail any request to "create" an existing index with different settings than the existing one. The error code and message should be explicit about the problem, for example:

{ err : "Cannot create index 'myNewIndex', index exists with different attributes", code : <new code>, ok : 0.0 }

If we wanted (in a separate ticket) to add a feature to convert an index on-the-fly, that might have some value, but since the workaround is to drop the current index and create a new one with the desired settings, all we really need here is to return an error.

Comment by Daniel Doubrovkine [ 13/Oct/12 ]

For what it's worth, it took me half a day to narrow a problem to this one - we were "sure" that we have a unique index on something and were still seeing dup data.

Comment by Robert Stam [ 30/Apr/12 ]

Craig and I recently went back and forth many times with a user who was complaining that his unique index wasn't working only to finally find out that his calls to createIndex with

{unique:true}

we're being silently ignored because of a pre-existing index that was not unique.

I'm not sure what the second call to createIndex should do (recreate the index or give an error message), but silently doing nothing is definitely not the right thing.

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