[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: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
db.foo.ensureIndex( {a : 1}); ); ); 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 |
| Comment by Marcel Bankmann [ 05/Jul/12 ] |
|
version: 2.0.6 |
| 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. |