DBAtlas · Database operations atlas

85 IndexOptionsConflict: Index already exists with different options / different name

MongoDB

What does it mean?

The index you are creating conflicts with an existing one: an index with the same name has different options, or an equivalent index with the same key and options already exists under another name. MongoDB does not let you re-create the same index with a conflicting definition.

Why does it happen?

Creating an index with the same name and key but different options (e.g. expireAfterSeconds, partialFilterExpression, collation); or redefining the equivalent of an existing index under a different name ('Index already exists with a different name'). Index definitions drifting over time in application/migration scripts is the typical cause. Same name with a different key gives 86 IndexKeySpecsConflict instead.

How to fix it

View the existing index: db.my_collection.getIndexes(). If you really want to change the options, drop the old index and create the new one: db.my_collection.dropIndex('index_name') then createIndex(...). Otherwise make the definition match the existing index exactly, or give the new index a different name. Make migration scripts idempotent.

Open in DBAtlas →

More from this engine