mongodb/node-mongodb-native · error · MongoDecompressionError
Server sent message compressed using an unsupported…
Error message
Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID}) What it means
Thrown by decompress() in the wire protocol layer when a server response arrives marked as OP_COMPRESSED but carries a compressorID byte outside the recognized set (0=none, 1=snappy, 2=zlib, 3=zstd). The driver cannot decode the payload because no handler exists for that ID, so the entire response is unusable. It surfaces as a MongoDecompressionError. This typically indicates byte corruption on the wire, a man-in-the-middle/proxy rewriting frames, or a server using a compressor the client driver version does not yet support.
Solutions
- Remove or empty the 'compressors' option in your MongoClientOptions so compression is not negotiated (fastest workaround).
- Upgrade the mongodb driver to the latest version in case the compressor ID is newly supported.
- Disable any proxy, sidecar, or packet inspector between the client and mongod/mongos and retest against the server directly.
- Capture the traffic and confirm the server's hello response compressor list; if it advertises an ID the driver cannot handle, upgrade or reconfigure mongod.
- Open a MongoDB server ticket if a stable server advertises a compressor ID absent from the driver's Compressor map.
Example fix
// before
const client = new MongoClient(uri, { compressors: ['zstd'] });
// after (disable compression to isolate the failure)
const client = new MongoClient(uri); Defensive patterns
Strategy: try-catch
Try / catch
try {
await collection.find({}).toArray();
} catch (error) {
if (error instanceof MongoDecompressionError) {
}
} Prevention
- Only enable compression against genuine mongod/mongos with no traffic-altering proxy.
- Pin known-good snappy/zstd/zlib native dependency versions.
- Keep driver and server versions within the supported compatibility matrix.
When it happens
Trigger: Occurs only when compression is enabled in client options (compressors: ['zlib'|'snappy'|'zstd']) AND the server agreed to compress AND a returned OP_COMPRESSED frame's compressorID byte at offset headerSize+8 is not 0,1,2, or 3. Fires inside decompressResponse -> decompress at src/cmap/wire_protocol/compression.ts:120 during response reading on any compressed command.
Common situations: A corporate proxy or load balancer (e.g. HAProxy with protobuf-aware rewriting, a debugging MITM) mangles MongoDB wire frames; running against a prerelease/newer server that introduced a new compressor before the driver shipped support; network hardware bit-flips; a stale connection pool reusing a socket after the server changed its compression config mid-session.
Related errors
- Message body and message header must be the same length
- is not a valid compression mechanism. Must be one of: .
- compressors must be an array or a comma-delimited list of…
- OP_REPLY numberReturned is an invalid array length
- Unknown compressor failed to compress
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/c2ae303ccf04a388.
Report an issue: GitHub.
Appendix: 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 dce7939f86)