KeystoneJS - Create new Item throws duplicate key error
Completely delete the model from MongoDB and restart. I typically see this error when making changes to a model with indexes that have been defined previously
with insert new item,you should set an default value for 'name', because name is set unique=true.in my case, key is set to unique.
before:
MongoDB Enterprise > db.categories.save({_id: 89,name: 'xxx'})WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: sku.productcategories index: key_1 dup key: { : null }" }})
after:
MongoDB Enterprise > db.categories.save({_id: 89,name: 'xxx', key:'xx'})WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 89 })