mongodb/node-mongodb-native · error · MongoUnexpectedServerResponseError
Error with validation data
Error message
Error with validation data
What it means
Thrown by ValidateCollectionOperation.handleOk when the server's validate response includes a 'result' field that is neither null nor a string. The driver expects result to be a textual summary string (or absent); any non-string result indicates an unexpected/malformed server response. MongoUnexpectedServerResponseError - the server replied with a shape the driver cannot interpret.
Source
Thrown at src/operations/validate_collection.ts:42
this.collectionName = collectionName;
}
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
- Check server and driver versions and align them per the compatibility matrix (often upgrading the driver resolves response-shape mismatches).
- Run db.runCommand({ validate: 'collName' }) directly to inspect the raw response shape.
- If the shape genuinely changed upstream, file a driver issue.
- Catch MongoUnexpectedServerResponseError around validation tooling so a mismatched response doesn't abort the whole job.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const res = await db.admin().validateCollection(name);
} catch (e) {
if (e instanceof MongoUnexpectedServerResponseError && /validation data/.test(e.message)) {
// run db.runCommand({ validate: name }) to inspect the raw response shape; align driver/server versions
}
throw e;
} Prevention
- Keep driver and server versions within the compatibility matrix.
- Inspect raw validate responses when integrating new server versions.
- Isolate admin/ops calls so response-shape mismatches don't crash the app.
When it happens
Trigger: Calling db.admin().validateCollection(name) (or collection-level validate) against a server whose validate response uses a different schema for the result field - e.g., a newer server returning a structured object instead of a string, or a non-standard build.
Common situations: Driver/server version skew where validate's response format changed; managed-service customized responses; running an older driver against a newer server.
Related errors
- Illegal profiling level value ${was}
- Error with profile command
- Driver attempted to initialize in load balancing mode, but t
- Current topology does not support sessions
- BSON element "${name}" is missing
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/7cfb151abc478f64.json.
Report an issue: GitHub.