{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/operations/validate_collection.ts#L24-L51","documentation":"Thrown by ValidateCollectionOperation.handleOk (src/operations/validate_collection.ts:42) when the server's validate response has a 'result' field that is present but not a string. The driver expects the server to return a textual result summary; a non-string value indicates an unexpected server response shape. This is a MongoUnexpectedServerResponseError, meaning the server replied in a way the driver cannot interpret.","triggerScenarios":"Calling db.admin().validateCollection(name) against a server version or storage engine whose validate output shape differs from what the driver parses.","commonSituations":"Driver/server version mismatch, beta or dev server builds, or a corrupted/edge-case response from validate on an exotic storage engine.","solutions":["Verify the server version is supported by this driver version (consult compatibility matrix).","Upgrade the driver to a version that understands the server's validate response shape.","Run db.runCommand({ validate: 'collname' }) directly to inspect the raw server response."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await db.admin().validateCollection('myColl');\n} catch (e) {\n  if (e instanceof MongoUnexpectedServerResponseError && /validation data/.test(e.message)) {\n    // fall back to raw command for diagnostics\n    const raw = await db.command({ validate: 'myColl' });\n    console.error('raw validate output:', raw);\n  }\n  throw e;\n}","preventionTips":["Pin driver and server versions to a compatible matrix.","Use db.runCommand({ validate }) for finer control over output parsing.","Report unexpected response shapes to driver maintainers."],"tags":["server-response","validate","admin","compatibility"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}