mongodb/node-mongodb-native · error · MongoRuntimeError
OP_MSG Payload Type 1 detected unsupported protocol
Error message
OP_MSG Payload Type 1 detected unsupported protocol
What it means
Thrown while parsing an incoming OP_MSG wire-protocol message when a section with payloadType === 1 is encountered. The MongoDB wire protocol defines payload type 0 (a single BSON document) and type 1 (a sequence of documents), but the Node.js team decided no driver code path produces or consumes type 1, so the parser refuses it. In practice the server never sends type 1 to this driver, so seeing this error indicates a non-conforming peer, a man-in-the-middle, or memory corruption on the stream.
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 3366c21a63)
Solutions
- Confirm the URI host:port points at a real mongod/mongos and not another database or HTTP service.
- Disable any network proxies, debug proxies, or TLS-terminating middleboxes between the client and server and retry.
- Check driver and server versions are compatible (run a supported server version >= 3.6 which speaks OP_MSG).
- If reproducible, capture a packet capture (tcpdump) of the failing exchange and file a driver bug with the bytes preceding the error.
Example fix
// before
const client = new MongoClient('mongodb://localhost:5432'); // wrong service
// after
const client = new MongoClient('mongodb://localhost:27017'); // real mongod Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the target is a MongoDB service before relying on it
import { MongoClient } from 'mongodb';
async function assertMongo(uri: string) {
const c = new MongoClient(uri);
try {
await c.db().admin().ping();
return true;
} catch (e) {
return false;
} finally {
await c.close().catch(() => {});
}
} Type guard
import { MongoRuntimeError } from 'mongodb';
function isPayloadTypeError(e: unknown): e is MongoRuntimeError {
return e instanceof MongoRuntimeError &&
/Payload Type 1/.test(e.message);
} Try / catch
try {
await collection.findOne({}, { timeoutMS: 1000 });
} catch (e) {
if (isPayloadTypeError(e)) {
// peer is not speaking expected OP_MSG framing; surface to ops
throw new Error('Target at ' + uri + ' is not a conforming MongoDB server');
}
throw e;
} Prevention
- Always construct URIs from known mongod/mongos endpoints rather than discovery.
- Avoid pointing MongoClient at opaque proxies that re-frame traffic.
- Run an admin.ping() health check at startup to fail fast on wrong-target errors.
When it happens
Trigger: Hit inside OnDemandDocument.parse() (src/cmap/commands.ts:747-752) while decoding any server reply that arrives as OP_MSG. Fires the moment the parser reads a payloadType byte equal to 1 for any section of the message. Triggered by connection.command()/sendWire() reading a response from any operation (query, write, handshake, heartbeat).
Common situations: Pointing the driver at a non-MongoDB service that speaks a similar-but-wrong protocol; a corrupted TCP/TLS stream producing garbage framing bytes; an intercepting proxy or debugger that re-frames the wire message; extremely rarely, a server bug or a forged/modified message.
Related errors
- Query document must be specified for query
- Message body and message header must be the same length
- Argument "size" must be a non-negative number
- Malformed JSON body in GET request.
- [Azure KMS] ${error.message}
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/65fc76c57151825d.json.
Report an issue: GitHub.