{"id":"7cfb151abc478f64","repo":"mongodb/node-mongodb-native","slug":"error-with-validation-data","errorCode":null,"errorMessage":"Error with validation data","messagePattern":"Error with validation data","errorType":"exception","errorClass":"MongoUnexpectedServerResponseError","httpStatus":null,"severity":"error","filePath":"src/operations/validate_collection.ts","lineNumber":42,"sourceCode":"    this.collectionName = collectionName;\n  }\n\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":24,"sourceCodeEnd":51,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/operations/validate_collection.ts#L24-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"Driver/server version skew where validate's response format changed; managed-service customized responses; running an older driver against a newer server.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await db.admin().validateCollection(name);\n} catch (e) {\n  if (e instanceof MongoUnexpectedServerResponseError && /validation data/.test(e.message)) {\n    // run db.runCommand({ validate: name }) to inspect the raw response shape; align driver/server versions\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["validate","admin","server-response","compatibility"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}