{
  "id": "mongodb/schema-validation-type-error",
  "signature": "MongoServerError: Document failed validation: Additional properties not allowed: 'extraField'",
  "signature_zh": "MongoServerError：文档验证失败：不允许额外属性：'extraField'",
  "regex": "Document failed validation: Additional properties not allowed",
  "domain": "mongodb",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "A document being inserted or updated violates the collection's JSON Schema validator that has additionalProperties set to false.",
  "root_cause_type": "generic",
  "root_cause_zh": "插入或更新的文档违反了集合的 JSON Schema 验证器，该验证器将 additionalProperties 设置为 false。",
  "versions": [
    {
      "version": "mongodb-3.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-4.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "mongodb-4.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This removes all data and validation, which is destructive and not a fix for the schema mismatch.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This bypasses validation entirely, defeating the purpose of schema enforcement.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The document will always fail validation unless it is modified.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Modify the document to remove the extra field before insertion. Example in Node.js: delete doc.extraField; await collection.insertOne(doc);",
      "success_rate": 0.9,
      "how": "Modify the document to remove the extra field before insertion. Example in Node.js: delete doc.extraField; await collection.insertOne(doc);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Update the collection validator to allow the extra field: db.runCommand({ collMod: 'mycollection', validator: { $jsonSchema: { bsonType: 'object', additionalProperties: true, properties: { extraField: { bsonType: 'string' } } } } })",
      "success_rate": 0.85,
      "how": "Update the collection validator to allow the extra field: db.runCommand({ collMod: 'mycollection', validator: { $jsonSchema: { bsonType: 'object', additionalProperties: true, properties: { extraField: { bsonType: 'string' } } } } })",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use validationAction: 'warn' instead of 'error' to log violations without blocking writes: db.runCommand({ collMod: 'mycollection', validationAction: 'warn' })",
      "success_rate": 0.8,
      "how": "Use validationAction: 'warn' instead of 'error' to log violations without blocking writes: db.runCommand({ collMod: 'mycollection', validationAction: 'warn' })",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Modify the document to remove the extra field before insertion. Example in Node.js: delete doc.extraField; await collection.insertOne(doc);",
    "Update the collection validator to allow the extra field: db.runCommand({ collMod: 'mycollection', validator: { $jsonSchema: { bsonType: 'object', additionalProperties: true, properties: { extraField: { bsonType: 'string' } } } } })",
    "Use validationAction: 'warn' instead of 'error' to log violations without blocking writes: db.runCommand({ collMod: 'mycollection', validationAction: 'warn' })"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.mongodb.com/docs/manual/core/schema-validation/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}