DBAtlas · Database operations atlas

86 IndexKeySpecsConflict: IndexKeySpecsConflict

MongoDB

What does it mean?

The index being created has the same key specification (same fields/order) as an existing index but different options or a different name. MongoDB does not allow two conflicting index definitions with the same key.

Why does it happen?

An attempt was made to create a second index on the same field(s) with a different name or different options (e.g. different collation, partialFilterExpression, unique setting). It usually happens when an index definition is changed in a migration/code and re-run.

How to fix it

Inspect the existing indexes: db.collection.getIndexes() Find the conflicting index with the same key. To switch to the options you want, first drop the old index (dropIndex), then recreate it with the new definition. If only the name differs, keep using the existing index; do not create an unnecessary second definition.

Open in DBAtlas →

More from this engine