{"record":{"id":"cb5e9e154cf8d3de","repo":"mongodb/node-mongodb-native","slug":"unknown-compressor-options-agreedcompressor-fai","errorCode":null,"errorMessage":"Unknown compressor ${options.agreedCompressor} failed to compress","messagePattern":"Unknown compressor (.+?) failed to compress","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/wire_protocol/compression.ts","lineNumber":102,"sourceCode":"    case 'snappy': {\n      Snappy ??= loadSnappy();\n      return await Snappy.compress(dataToBeCompressed);\n    }\n    case 'zstd': {\n      loadZstd();\n      if ('kModuleError' in zstd) {\n        throw zstd['kModuleError'];\n      }\n      return await zstd.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL);\n    }\n    case 'zlib': {\n      if (options.zlibCompressionLevel) {\n        zlibOptions.level = options.zlibCompressionLevel;\n      }\n      return await zlibDeflate(dataToBeCompressed, zlibOptions);\n    }\n    default: {\n      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(","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/wire_protocol/compression.ts#L84-L120","documentation":"A MongoInvalidArgumentError thrown in the compress() function's default switch case when options.agreedCompressor is not one of 'snappy', 'zstd', 'zlib'. The compressor is negotiated during handshake from the compressors connection-string option; reaching the default case means an unrecognized compressor value was agreed upon, which indicates corruption in the negotiated state or an invalid input to the compression layer.","triggerScenarios":"The connection's agreedCompressor field holds a value outside the known set. For end users this arises when the compressors connection-string option contains a typo or unsupported name (e.g., 'gzip', 'lz4') that somehow propagated, or via internal corruption of the description object.","commonSituations":"Typo in ?compressors= (e.g., 'gzip' instead of 'zlib', 'snapp' instead of 'snappy'); passing an unsupported compressor name; a custom/forked driver adding a compressor without updating the switch; version skew where a compressor was renamed.","solutions":["Use only supported compressors: 'snappy', 'zstd', 'zlib' (or omit compressors for none).","Correct typos in the compressors connection-string parameter.","Install optional native deps: npm install snappy and/or mongodb-js/zstd for the chosen compressor.","Upgrade the driver if using a version with a compression-negotiation bug."],"exampleFix":"// before\nconst client = new MongoClient('mongodb://host/?compressors=gzip');\n\n// after\nconst client = new MongoClient('mongodb://host/?compressors=zlib');","handlingStrategy":"validation","validationCode":"const VALID = ['none','snappy','zstd','zlib'];\nfor (const c of compressors) {\n  if (!VALID.includes(c)) throw new Error(`Unsupported compressor: ${c}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only supported compressors: snappy, zstd, zlib.","Install optional native deps (snappy, zstd) for the chosen compressor.","Validate compressor names at config load."],"tags":["compression","protocol","config","wire-protocol"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}