{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/validate_collection.ts#L26-L51","documentation":"Thrown by ValidateCollectionOperation.handleOk (src/operations/validate_collection.ts:44) when the validate response text matches /exception|corrupt/. The server itself reported an exception or corruption during validation, so the driver rethrows as MongoUnexpectedServerResponseError with the collection name. This indicates the collection's data is damaged on the server side.","triggerScenarios":"Calling db.admin().validateCollection(name) where the server's validate output contains 'exception' or 'corrupt' (BSON/data corruption on disk).","commonSituations":"Disk failures, unclean shutdowns, storage-engine corruption, or running validate against a collection with known integrity problems.","solutions":["Inspect the full validate output via db.runCommand({ validate: 'collname', full: true }) to identify corrupt documents.","Restore the affected collection from backup or resync from a healthy replica-set member.","Run db.repairDatabase() or contact MongoDB support for catastrophic corruption."],"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 && /Invalid collection/.test(e.message)) {\n    // page on-call; data corruption suspected\n  }\n  throw e;\n}","preventionTips":["Run validateCollection during scheduled maintenance to detect corruption early.","Maintain tested backups for point-in-time recovery.","Monitor disk health and use journaling/WiredTiger checkpoints."],"tags":["validate","data-integrity","corruption","admin"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}