mongodb/node-mongodb-native · error · MongoUnexpectedServerResponseError

Error with validation data

Error message

Error with validation data

What it means

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.

Solutions

  1. Verify the server version is supported by this driver version (consult compatibility matrix).
  2. Upgrade the driver to a version that understands the server's validate response shape.
  3. Run db.runCommand({ validate: 'collname' }) directly to inspect the raw server response.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await db.admin().validateCollection('myColl');
} catch (e) {
  if (e instanceof MongoUnexpectedServerResponseError && /validation data/.test(e.message)) {
    // fall back to raw command for diagnostics
    const raw = await db.command({ validate: 'myColl' });
    console.error('raw validate output:', raw);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling db.admin().validateCollection(name) against a server version or storage engine whose validate output shape differs from what the driver parses.

Common situations: Driver/server version mismatch, beta or dev server builds, or a corrupted/edge-case response from validate on an exotic storage engine.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11). Data as JSON: /api/errors/7cfb151abc478f64. Report an issue: GitHub.

Appendix: 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 dce7939f86)