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

  1. Run a full (non-background) validate with full option and review the complete server output for specifics.
  2. If indexes are corrupt, drop and recreate the affected indexes.
  3. If data files are corrupt, resync from a healthy replica-set member (initial sync) or restore from backup.
  4. 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

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


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/acbe9f59065a909f.json. Report an issue: GitHub.