MongoDB E11000: Duplicate Key Error on Unique Index
E11000 duplicate key error collection: app.users index: email_1 dup key: { email: "user@example.com" }
Immediate Remediation
bash
db.users.getIndexes(); db.users.remove({ _id: ObjectId("<duplicate_doc_id>") }); -- or update the conflicting doc: db.users.updateOne({ _id: ObjectId("<duplicate_doc_id>" }, { $set: { email: "new+unique@example.com" } })Root Cause Analysis
A unique index constraint was violated because an insert or update attempted to store a value that already exists in the indexed field. This commonly occurs after enabling a unique index on an existing collection that already contains duplicates, or when application retry logic re-inserts the same document without an upsert.
Verification & Guardrails
- Before dropping a unique index, check for application code that relies on it for idempotency.
- If duplicates are expected, use upsert with a filter on the unique key instead of insert.
- For sharded clusters, the duplicate key error may reference the shard key; inspect the full error message for the index name.
Have a custom or uncategorized crash?
Run your trace through our in-memory client privacy sandbox for instant SRE remediation.