-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.6.5
-
Component/s: None
-
None
-
Environment:1.6.5 and 1.7.6
-
ALL
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"});
> db.fb.save(
);
> db.fb.save(
);
> db.fb.ensureIndex(
,
{unique:1, dropDupes:1});
E11000 duplicate key error index: test.fb.$name_1 dup key: { : "fred" }
> db.fb.ensureIndex(
,
{unique:true, dropDupes:true});
E11000 duplicate key error index: test.fb.$name_1 dup key: { : "fred" }
Business case:
- broken functionality
- duplicates
-
SERVER-2054 Creating an index with dropDups shouldn't assert
- Closed