mongodb/node-mongodb-native · critical · MongoRuntimeError

OP_MSG Payload Type 1 detected unsupported protocol

Error message

OP_MSG Payload Type 1 detected unsupported protocol

What it means

Thrown as a MongoRuntimeError in OpMsgResponse.parse() when an OP_MSG response section has payloadType === 1. The OP_MSG spec defines two payload types: type 0 (a single BSON document) and type 1 (a document sequence / Section 1). The driver supports sending type-1 sections but, per an explicit code comment ('no driver makes use of payload type 1'), it does not support receiving them. A type-1 section in a response is therefore treated as an unsupported protocol.

Solutions

  1. Point the driver at a genuine MongoDB server (community or Atlas)
  2. If using a MongoDB-compatible service, check its compatibility notes or upgrade it
  3. Capture the failing command and response and report it to the service vendor
Defensive patterns

Strategy: try-catch

Try / catch

try { await client.db().command({ ping: 1 }); } catch (e) {
  if (e instanceof MongoRuntimeError && /Payload Type 1/.test(e.message)) {
    // server/proxy is non-conformant; switch to a genuine MongoDB endpoint
  }
  throw e;
}

Prevention

When it happens

Trigger: A MongoDB server (or proxy) returns an OP_MSG response containing a payload type-1 section. Genuine MongoDB servers do not send type-1 responses for commands the driver issues, so this implies a non-conformant server, a custom backend, or wire-protocol corruption.

Common situations: Pointing the driver at a MongoDB-compatible but non-conformant service (e.g. a mock server, Amazon DocumentDB in certain modes, or a custom proxy) that emits type-1 sections; corrupted response bytes that happen to decode as payload type 1.

Related errors


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

Appendix: source

Thrown at src/cmap/commands.ts:751

    this.index = 4;

    while (this.index < this.data.length) {
      const payloadType = this.data[this.index++];
      if (payloadType === 0) {
        // BSON spec specifies that this is a 32-bit signed integer: https://bsonspec.org/spec.html#:~:text=%3A%3A%3D-,int32,-e_list%20unsigned_byte(0
        // While allowing negative sizes seems odd, in practice we never expect a negative size. Also, the server's 16mb limit for BSON documents leaves plenty
        // of room in an int32 to store a document of the max BSON size that the server supports
        const bsonSize = readInt32LE(this.data, this.index);
        const bin = this.data.subarray(this.index, this.index + bsonSize);

        this.sections.push(bin);

        this.index += bsonSize;
      } else if (payloadType === 1) {
        // It was decided that no driver makes use of payload type 1

        // TODO(NODE-3483): Replace with MongoDeprecationError
        throw new MongoRuntimeError('OP_MSG Payload Type 1 detected unsupported protocol');
      }
    }

    this.parsed = true;

    return this.sections[0];
  }
}

const MESSAGE_HEADER_SIZE = 16;
const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID

/**
 * @internal
 */
export interface OpCompressesRequestOptions {
  zlibCompressionLevel: number;
  agreedCompressor: CompressorName;

View on GitHub (pinned to dce7939f86)