{"id":"c2ae303ccf04a388","repo":"mongodb/node-mongodb-native","slug":"server-sent-message-compressed-using-an-unsupporte","errorCode":null,"errorMessage":"Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})","messagePattern":"Server sent message compressed using an unsupported compressor\\. \\(Received compressor ID (.+?)\\)","errorType":"exception","errorClass":"MongoDecompressionError","httpStatus":null,"severity":"error","filePath":"src/cmap/wire_protocol/compression.ts","lineNumber":120,"sourceCode":"      throw new MongoInvalidArgumentError(\n        `Unknown compressor ${options.agreedCompressor} failed to compress`\n      );\n    }\n  }\n}\n\n// Decompress a message using the given compressor\nexport async function decompress(\n  compressorID: number,\n  compressedData: Uint8Array\n): Promise<Uint8Array> {\n  if (\n    compressorID !== Compressor.snappy &&\n    compressorID !== Compressor.zstd &&\n    compressorID !== Compressor.zlib &&\n    compressorID !== Compressor.none\n  ) {\n    throw new MongoDecompressionError(\n      `Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`\n    );\n  }\n\n  switch (compressorID) {\n    case Compressor.snappy: {\n      Snappy ??= loadSnappy();\n      return await Snappy.uncompress(compressedData, { asBuffer: true });\n    }\n    case Compressor.zstd: {\n      loadZstd();\n      if ('kModuleError' in zstd) {\n        throw zstd['kModuleError'];\n      }\n      return await zstd.decompress(compressedData);\n    }\n    case Compressor.zlib: {\n      return await zlibInflate(compressedData);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/wire_protocol/compression.ts#L102-L138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew MongoClient('mongodb://host/?compressors=zstd'); // server uses id client doesn't know\n\n// after - align to a mutually supported compressor or disable\nnew MongoClient('mongodb://host/?compressors=zlib');","handlingStrategy":"try-catch","validationCode":"// Align client compressors with server-supported values before connecting.\n// Server-supported compressors are reported in hello/handshake; align client accordingly.\nconst SUPPORTED = new Set(['none', 'snappy', 'zlib', 'zstd']);\nfunction validateClientCompressors(uri) {\n  const c = new URL(uri).searchParams.get('compressors');\n  if (c) for (const part of c.split(',')) if (!SUPPORTED.has(part.toLowerCase())) throw new Error(`Client compressor ${part} not supported by this driver`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await collection.find({}).toArray();\n} catch (err) {\n  if (err instanceof MongoDecompressionError && /unsupported compressor/i.test(err.message)) {\n    // disable compression or upgrade driver, then reconnect\n    client = new MongoClient(uriWithoutCompression);\n    await client.connect();\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["compression","wire-protocol","server-compat","corruption"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}