11000: DuplicateKey (error code 11000)
MongoDBWhat does it mean?
The numeric code for the duplicate key error (returned together with the E11000 text). A write operation violated a unique index constraint.
Why does it happen?
Writing the same unique field again, concurrent upserts generating the same key, or duplicate documents in a bulk write.
How to fix it
Catch error code 11000 in application code and implement idempotent behavior (update if it exists, insert otherwise). In bulk operations, use ordered:false to allow documents other than the duplicates to be written. Review the uniqueness rule and the index definition.