{
  "id": "database/mongodb-cannot-create-index-duplicate-key",
  "signature": "MongoServerError: Cannot create index 'idx_email_unique': a unique index on field 'email' already exists with different options",
  "signature_zh": "MongoServerError: 无法创建索引 'idx_email_unique'：字段 'email' 上已存在一个具有不同选项的唯一索引",
  "regex": "Cannot create index.*unique index on field.*already exists with different options",
  "domain": "database",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "An existing unique index on the same field has different options (e.g., collation, sparse, partial filter expression) than the new index being created, causing a conflict.",
  "root_cause_type": "generic",
  "root_cause_zh": "同一字段上已存在的唯一索引与新创建的索引具有不同的选项（例如，排序规则、稀疏、部分过滤器表达式），导致冲突。",
  "versions": [
    {
      "version": "MongoDB 5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MongoDB 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Drop the existing index with db.collection.dropIndex() and recreate it with the same name but different options",
      "why_fails": "If the existing index is being used by an application, dropping it may cause query performance degradation or application errors until the new index is created",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Create the index with the force: true option",
      "why_fails": "MongoDB does not support a 'force' option for index creation; this will result in a syntax error",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the error and assume the index already exists",
      "why_fails": "The existing index may have different collation or options, leading to unexpected behavior in queries or uniqueness enforcement",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "List existing indexes on the collection: `db.collection.getIndexes()`. Identify the conflicting index and drop it: `db.collection.dropIndex('idx_email_unique')`. Then create the new index with the desired options: `db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique', collation: {locale: 'en', strength: 2}})`",
      "success_rate": 0.9,
      "how": "List existing indexes on the collection: `db.collection.getIndexes()`. Identify the conflicting index and drop it: `db.collection.dropIndex('idx_email_unique')`. Then create the new index with the desired options: `db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique', collation: {locale: 'en', strength: 2}})`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the existing index has different options but you want to keep it, rename the new index to a different name: `db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique_v2'})`",
      "success_rate": 0.85,
      "how": "If the existing index has different options but you want to keep it, rename the new index to a different name: `db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique_v2'})`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "列出集合上的现有索引：`db.collection.getIndexes()`。识别冲突索引并删除它：`db.collection.dropIndex('idx_email_unique')`。然后使用所需选项创建新索引：`db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique', collation: {locale: 'en', strength: 2}})`",
    "如果现有索引具有不同选项但您想保留它，将新索引重命名为不同名称：`db.collection.createIndex({email: 1}, {unique: true, name: 'idx_email_unique_v2'})`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-09-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}