[SERVER-2580] ensureIndex with unique:true and dropDups:true fails if duplicate data present Created: 17/Feb/11 Updated: 02/Mar/11 Resolved: 02/Mar/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 1.6.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alvin Richards (Inactive) | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
1.6.5 and 1.7.6 |
||
| Issue Links: |
|
||||||||||||
| Operating System: | ALL | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
Problem: From the documentation http://www.mongodb.org/display/DOCS/Indexes A unique index cannot be created on a key that has duplicate values. If you would like to create the index anyway, keeping the first document the database indexes and deleting all subsequent documents that have duplicate values, add the dropDups option. db.things.ensureIndex( {firstname : 1}, {unique : true, dropDups : true}) However, this appears to be broken, since its errors out with E11000 duplicate key error index: test.fb.$name_1 dup key: { : "fred" } Reproduce: > db.fb.save( {name:"fred"}); ); ); , {unique:1, dropDupes:1}); , {unique:true, dropDupes:true}); Business case:
|
| Comments |
| Comment by Alvin Richards (Inactive) [ 17/Feb/11 ] |
|
Duplicate issue of |
| Comment by Eliot Horowitz (Inactive) [ 17/Feb/11 ] |
|
You're probably just seeing: |
| Comment by Eliot Horowitz (Inactive) [ 17/Feb/11 ] |
|
Was the index created successfully? |
| Comment by Alvin Richards (Inactive) [ 17/Feb/11 ] |
|
Sorry, cut & pasted the wrong example > db.fb.ensureIndex( {name:1}, {unique:1, dropDups:1}); > db.fb.ensureIndex( {name:1}, {unique:true, dropDups:true}); |
| Comment by Eliot Horowitz (Inactive) [ 17/Feb/11 ] |
|
Type, dropDups vs dropDupes |