mongodb/node-mongodb-native · critical · MongoUnexpectedServerResponseError
Invalid collection ${this.collectionName}
Error message
Invalid collection ${this.collectionName} What it means
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.
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 3366c21a63)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await db.admin().validateCollection(name);
} catch (e) {
if (e instanceof MongoUnexpectedServerResponseError && /exception|corrupt/.test(e.message)) {
// serious: run full validate, rebuild indexes, resync/restore; page ops
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- OP_REPLY numberReturned is an invalid array length ${this.nu
- Server sent message compressed using an unsupported compress
- Message body and message header must be the same length
- Negative binary type element size found for subtype 0x02
- Binary type with subtype 0x02 contains too long binary size
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/acbe9f59065a909f.json.
Report an issue: GitHub.