{
  "id": "database/mongodb-cannot-create-collection-options-conflict",
  "signature": "MongoServerError: Collection already exists. Options in createCollection command conflict with existing collection options",
  "signature_zh": "MongoServerError: 集合已存在。createCollection 命令中的选项与现有集合选项冲突",
  "regex": "Collection already exists\\. Options in createCollection command conflict with existing collection options",
  "domain": "database",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "A collection with the same name already exists but with different options (e.g., different collation, validation rules, or storage engine settings) than those specified in the createCollection command.",
  "root_cause_type": "generic",
  "root_cause_zh": "同名的集合已存在，但其选项（例如，不同的排序规则、验证规则或存储引擎设置）与 createCollection 命令中指定的选项不同。",
  "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 collection and recreate it with the desired options",
      "why_fails": "Dropping the collection will delete all data permanently; this is irreversible unless you have a backup",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the error and use the collection as-is",
      "why_fails": "If the existing collection has different options (e.g., missing a required validator), your application may behave incorrectly or fail to enforce data integrity",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the collMod command to change options on the existing collection",
      "why_fails": "collMod can only modify certain options like validation rules and indexes, but cannot change fundamental options like collation or storage engine",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check the existing collection options with `db.getCollectionInfos({name: 'mycollection'})`. If the options are acceptable, use the existing collection without modification. If not, rename the old collection: `db.mycollection.renameCollection('mycollection_old')` and then create the new one with desired options: `db.createCollection('mycollection', {collation: {locale: 'en', strength: 2}, validator: {email: {$type: 'string'}}})`",
      "success_rate": 0.85,
      "how": "Check the existing collection options with `db.getCollectionInfos({name: 'mycollection'})`. If the options are acceptable, use the existing collection without modification. If not, rename the old collection: `db.mycollection.renameCollection('mycollection_old')` and then create the new one with desired options: `db.createCollection('mycollection', {collation: {locale: 'en', strength: 2}, validator: {email: {$type: 'string'}}})`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use collMod to modify compatible options: `db.runCommand({collMod: 'mycollection', validator: {email: {$type: 'string'}}, validationLevel: 'strict'})`. For collation, you must drop and recreate the collection.",
      "success_rate": 0.7,
      "how": "Use collMod to modify compatible options: `db.runCommand({collMod: 'mycollection', validator: {email: {$type: 'string'}}, validationLevel: 'strict'})`. For collation, you must drop and recreate the collection.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 `db.getCollectionInfos({name: 'mycollection'})` 检查现有集合选项。如果选项可接受，直接使用现有集合而不修改。如果不行，重命名旧集合：`db.mycollection.renameCollection('mycollection_old')` 然后使用所需选项创建新集合：`db.createCollection('mycollection', {collation: {locale: 'en', strength: 2}, validator: {email: {$type: 'string'}}})`",
    "使用 collMod 修改兼容选项：`db.runCommand({collMod: 'mycollection', validator: {email: {$type: 'string'}}, validationLevel: 'strict'})`。对于排序规则，必须删除并重新创建集合。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/reference/method/db.createCollection/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-11-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}