E11000 duplicate key error index in mongodb. I found this error after migrating my field from “unique” to “non-unique”. And in this problem we use mongoengine for flask.
First, i have a model such as bellow
class Tag(db.Document):
title = db.StringField(max_length=50, unique=True)
and then, i need to change it without unique.
class Tag(db.Document):
title = db.StringField(max_length=255, required=True)
And we found this error:
mongoengine.errors.NotUniqueError
NotUniqueError: Tried to save duplicate unique keys (insertDocument :: caused by :: 11000 E11000 duplicate key error index: myblog.tag.$name_1 dup key: { : null })
I found this answer to solve it: http://stackoverflow.com/questions/24430220/e11000…
$ mongo
> use yourdatabase;
> db.yourtable.getIndexes()
> db.yourtable.dropIndexes()
For example on my databases:
$ mongo
> use mysimpleblog;
> db.tag.getIndexes()
> db.tag.dropIndexes()
Hope it usefull..