85 IndexOptionsConflict: Index already exists with different options / different name(索引已存在但选项不同/名称不同)
MongoDB含义
要创建的索引与已有索引冲突:同名索引的选项不同,或已有键和选项相同的等价索引以其他名称存在。MongoDB 不允许以冲突的定义重新创建同一索引。
原因
以相同名称和键但不同选项(例如 expireAfterSeconds、partialFilterExpression、collation)创建索引;或以不同名称重新定义已有索引的等价索引('Index already exists with a different name')。应用/迁移脚本中的索引定义随时间漂移是典型原因。名称相同但键不同时,返回的是 86 IndexKeySpecsConflict。
解决方法
查看已有索引:db.my_collection.getIndexes()。如果确实要更改选项,删除旧索引后创建新索引:db.my_collection.dropIndex('index_name') 然后 createIndex(...)。否则,使定义与已有索引完全一致,或为新索引取不同的名称。使迁移脚本幂等。
同一数据库的其他条目
- 20 IllegalOperationIllegal operation(非法操作)
- 48 NamespaceExistsNamespace (collection) already exists(命名空间(集合)已存在)
- 11601 InterruptedOperation was interrupted(操作被中断)
- 67 CannotCreateIndexCannot create index(无法创建索引)
- 27 IndexNotFoundIndex not found(未找到索引)
- 79 UnknownReplWriteConcernUnknown replica set write concern(未知的副本集写关注)
- 10107 NotWritablePrimarynot master / not writable primary(不是 master / 不是可写的主节点)