mongodb/node-mongodb-native · critical · MongoUnexpectedServerResponseError
Invalid collection
Error message
Invalid collection ${this.collectionName} What it means
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.
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await db.admin().validateCollection(name);
} catch (e) {
if (e instanceof MongoUnexpectedServerResponseError && /Invalid collection/.test(e.message)) {
// page on-call; data corruption suspected
}
throw e;
} Prevention
- 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.
When it happens
Trigger: Calling db.admin().validateCollection(name) where the server's validate output contains 'exception' or 'corrupt' (BSON/data corruption on disk).
Common situations: Disk failures, unclean shutdowns, storage-engine corruption, or running validate against a collection with known integrity problems.
Related errors
- Error with validation data
- Binary type with subtype 0x02 contains too long binary size
- Binary type with subtype 0x02 contains too short binary size
- Message body and message header must be the same length
- Negative binary type element size found for subtype 0x02
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/acbe9f59065a909f.
Report an issue: GitHub.
Appendix: source
Thrown at src/operations/validate_collection.ts:44
override get commandName() {
return 'validate' as const;
}
override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
// Decorate command with extra options
return {
validate: this.collectionName,
...Object.fromEntries(Object.entries(this.options).filter(entry => entry[0] !== 'session'))
};
}
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
const result = super.handleOk(response);
if (result.result != null && typeof result.result !== 'string')
throw new MongoUnexpectedServerResponseError('Error with validation data');
if (result.result != null && result.result.match(/exception|corrupt/) != null)
throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);
if (result.valid != null && !result.valid)
throw new MongoUnexpectedServerResponseError(`Invalid collection ${this.collectionName}`);
return response;
}
}
View on GitHub (pinned to dce7939f86)