Mongo Giving ‘duplicate key error’ on non-unique fields

Mongoose doesn’t remove existing indexes so you’ll need to explicitly drop the index to get rid of it. In the shell:

> db.items.dropIndex('assets.serial_1')

This will happen if you initially define that field unique: true but then later remove that from the schema definition or change it to unique: false.

Leave a Comment