{"id":"acbe9f59065a909f","repo":"mongodb/node-mongodb-native","slug":"invalid-collection-this-collectionname","errorCode":null,"errorMessage":"Invalid collection ${this.collectionName}","messagePattern":"Invalid collection (.+?)","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"critical","filePath":"src/operations/validate_collection.ts","lineNumber":44,"sourceCode":"\n  override get commandName() {\n    return 'validate' as const;\n  }\n\n  override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {\n    // Decorate command with extra options\n    return {\n      validate: this.collectionName,\n      ...Object.fromEntries(Object.entries(this.options).filter(entry => entry[0] !== 'session'))\n    };\n  }\n\n  override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {\n    const result = super.handleOk(response);\n    if (result.result != null && typeof result.result !== 'string')\n      throw new MongoUnexpectedServerResponseError('Error with validation data');\n    if (result.result != null && result.result.match(/exception|corrupt/) != null)\n      throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);\n    if (result.valid != null && !result.valid)\n      throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);\n\n    return response;\n  }\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/operations/validate_collection.ts#L26-L51","documentation":"Thrown by ValidateCollectionOperation.handleOk when the validate response's 'result' string matches /exception|corrupt/. This indicates MongoDB itself detected corruption or an exception while scanning the collection - the data structure is damaged. MongoUnexpectedServerResponseError surfaced from a real server-side validation failure.","triggerScenarios":"Calling validateCollection on a collection whose underlying data files or indexes are corrupt; after an unclean shutdown, disk fault, or storage-engine error that left the collection in a bad state; the validate output literally contains 'exception' or 'corrupt'.","commonSituations":"Post-incident recovery (power loss, disk full, hardware fault); replica-set member with damaged files; index corruption after a forced kill; migrations/imports that produced malformed data.","solutions":["Run a full (non-background) validate with full option and review the complete server output for specifics.","If indexes are corrupt, drop and recreate the affected indexes.","If data files are corrupt, resync from a healthy replica-set member (initial sync) or restore from backup.","Engage MongoDB support/ops - 'corrupt' in validate output is a serious data-integrity signal."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await db.admin().validateCollection(name);\n} catch (e) {\n  if (e instanceof MongoUnexpectedServerResponseError && /exception|corrupt/.test(e.message)) {\n    // serious: run full validate, rebuild indexes, resync/restore; page ops\n  }\n  throw e;\n}","preventionTips":["Schedule regular validate checks to detect corruption early.","Ensure clean shutdowns and reliable storage to reduce corruption risk.","Maintain tested backups and a resync procedure for replica-set members."],"tags":["validate","corruption","data-integrity","recovery"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}