mongodb/node-mongodb-native · error · MongoDecompressionError
Server sent message compressed using an unsupported compress
Error message
Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID}) What it means
Thrown by decompress() when the compressor ID byte in an incoming OP_COMPRESSED message is not one of the known IDs (snappy, zstd, zlib, none). The server sent a message compressed with a compressor the client does not recognize, so it cannot be decompressed. Surfaced as MongoDecompressionError. This reflects a client/server compressor capability mismatch or a corrupted message header.
Source
Thrown at src/cmap/wire_protocol/compression.ts:120
throw new MongoInvalidArgumentError(
`Unknown compressor ${options.agreedCompressor} failed to compress`
);
}
}
}
// Decompress a message using the given compressor
export async function decompress(
compressorID: number,
compressedData: Uint8Array
): Promise<Uint8Array> {
if (
compressorID !== Compressor.snappy &&
compressorID !== Compressor.zstd &&
compressorID !== Compressor.zlib &&
compressorID !== Compressor.none
) {
throw new MongoDecompressionError(
`Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`
);
}
switch (compressorID) {
case Compressor.snappy: {
Snappy ??= loadSnappy();
return await Snappy.uncompress(compressedData, { asBuffer: true });
}
case Compressor.zstd: {
loadZstd();
if ('kModuleError' in zstd) {
throw zstd['kModuleError'];
}
return await zstd.decompress(compressedData);
}
case Compressor.zlib: {
return await zlibInflate(compressedData);View on GitHub (pinned to 3366c21a63)
Solutions
- Upgrade the driver to a version that supports the compressor the server is using.
- Disable compression (`?compressors=` omitted, or set to none) on the client to avoid compressed responses while diagnosing.
- Remove any proxy/LB that may be rewriting or corrupting wire-protocol message headers between client and server.
- Verify the server's supported compressors and align the client's `compressors` option to a mutually-supported value.
Example fix
// before
new MongoClient('mongodb://host/?compressors=zstd'); // server uses id client doesn't know
// after - align to a mutually supported compressor or disable
new MongoClient('mongodb://host/?compressors=zlib'); Defensive patterns
Strategy: try-catch
Validate before calling
// Align client compressors with server-supported values before connecting.
// Server-supported compressors are reported in hello/handshake; align client accordingly.
const SUPPORTED = new Set(['none', 'snappy', 'zlib', 'zstd']);
function validateClientCompressors(uri) {
const c = new URL(uri).searchParams.get('compressors');
if (c) for (const part of c.split(',')) if (!SUPPORTED.has(part.toLowerCase())) throw new Error(`Client compressor ${part} not supported by this driver`);
} Try / catch
try {
await collection.find({}).toArray();
} catch (err) {
if (err instanceof MongoDecompressionError && /unsupported compressor/i.test(err.message)) {
// disable compression or upgrade driver, then reconnect
client = new MongoClient(uriWithoutCompression);
await client.connect();
}
throw err;
} Prevention
- Use a mutually-supported compressor for both client and server.
- Upgrade the driver to a version supporting the server's compressors.
- Disable compression if a compressor mismatch cannot be resolved.
When it happens
Trigger: An OP_COMPRESSED response arrives whose compressorID byte is outside {0:none, 1:snappy, 2:zlib, 3:zstd}. Happens when the server believes a compressor was agreed that the client did not (negotiation mismatch), or when the message bytes are corrupted such that the compressorID field reads as an unknown value. Triggered by any operation that receives a compressed response.
Common situations: Server version that supports a compressor the client driver version does not (e.g. a newer compressor id). Corruption on the wire or from a misbehaving proxy/load balancer that rewrites message headers. Mismatch between driver and server about which compressor was negotiated during handshake.
Related errors
- Message body and message header must be the same length
- OP_REPLY numberReturned is an invalid array length ${this.nu
- Unknown compressor ${options.agreedCompressor} failed to com
- Server nonce does not begin with client nonce
- Server returned an invalid host: "${host}"
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/c2ae303ccf04a388.json.
Report an issue: GitHub.