0

I want to create Index by ensureIndex at name with parameter:dropDups,cause my collection books has two documents' name is "0book".

db.books.ensureIndex({name:1},{unique:true,dropDups:true})
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "errmsg" : "exception: E11000 duplicate key error index: 
     foobar.books.$name_1 dup key: { : \"0book\" }",
    "code" : 11000,
    "ok" : 0
}

Otherwise,it alerts me to the errmsg as above.

I don't know how to use pramater "dropDups",when create index in mongodb

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
brolanda
  • 63
  • 6
  • possible duplicate of [dropDups true not working mongodb](http://stackoverflow.com/questions/29747062/dropdups-true-not-working-mongodb) – Blakes Seven Sep 07 '15 at 07:31
  • Better example with answer : [remove dups from mongodb](http://stackoverflow.com/a/31558107/5031275) – Blakes Seven Sep 07 '15 at 07:35

0 Answers0