[SERVER-2699] ensureIndex() fails to create unique index if non-unique index already exists Created: 07/Mar/11  Updated: 15/Feb/13  Resolved: 04/Sep/12

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

Type: Bug Priority: Major - P3
Reporter: Daniel Pasette (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, single instance, no shards


Issue Links:
Duplicate
duplicates SERVER-2618 Attempting to create a new index that... Closed
Operating System: ALL
Participants:

 Description   

db.foo.ensureIndex(

{a : 1}

);
db.foo.save(

{key:1, a:1}

);
db.foo.save(

{key:2, a:2}

);

db.foo.ensureIndex(

{a : 1}

,

{name:'uniquea', unique:true}

);

db.foo.getIndexes() shows that 'uniquea' has not been created. While we should be checking to avoid creating exact duplicate indexes, my attempt to create a new unique index should succeed, because there isn't already a unique one. I might be doing this in preparation for replacing the (non-unique) 'a_1' index with 'uniquea'.



 Comments   
Comment by Dave Brondsema [ 04/Sep/12 ]

This appears to be the same as SERVER-2618

Comment by Marcel Bankmann [ 05/Jul/12 ]

version: 2.0.6
just ran into the same issue. the worst about this is the complete absence of a warning about it.

Comment by Yuen Ho Wong [ 20/Mar/11 ]

It seems that ensureIndex() only really does what it's name suggests, it ensures an index is already in place. If there's an index already, even if subsequent ensureIndex() calls are issued with different parameters, it doesn't attempt to change the index. Even worse, there's no warning or error returned to respond to the caller's intention.

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