{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/wire_protocol/compression.ts#L84-L120","documentation":"Thrown by the compress() helper when options.agreedCompressor is not one of the supported compressors ('snappy', 'zstd', 'zlib'). The driver and server negotiate a single agreed compressor during the handshake; attempting to compress an outgoing message with any other value is an invalid state. Surfaced as MongoInvalidArgumentError. The agreed compressor should only ever be one of the three supported names (or 'none', which skips compression).","triggerScenarios":"compress() is called with an agreedCompressor value outside the snappy/zstd/zlib set. This is normally driven internally by the negotiated compressor from the handshake; a user trigger requires manually passing a bad compressor into compressCommand description, or corrupting the compressor negotiation. Most often reflects a bug or a tampered options object rather than normal use.","commonSituations":"Passing a custom/typo'd compressor string in the connection string `compressors=zlibb`. A wrapper that overwrites the agreed compressor on the connection description. Future/unsupported compressor names not recognized by the installed driver version.","solutions":["Use only supported compressors in the connection string: `?compressors=zlib` or `?compressors=zstd` or `?compressors=snappy`.","If you pass a description/agreedCompressor programmatically, ensure it is one of 'snappy','zstd','zlib'.","Remove the compressors option entirely to disable compression and confirm the error disappears, then re-add a valid value."],"exampleFix":"// before\nnew MongoClient('mongodb://host/?compressors=lz4'); // unsupported\n\n// after\nnew MongoClient('mongodb://host/?compressors=zlib');","handlingStrategy":"validation","validationCode":"const VALID_COMPRESSORS = new Set(['none', 'snappy', 'zlib', 'zstd']);\nfunction validateCompressors(uri) {\n  const c = new URL(uri).searchParams.get('compressors');\n  if (c) for (const part of c.split(',')) if (!VALID_COMPRESSORS.has(part.toLowerCase())) throw new Error(`Unsupported compressor: ${part}`);\n}\nvalidateCompressors(process.env.MONGODB_URI);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only 'snappy', 'zlib', 'zstd' (or omit) in the compressors connection option.","Do not overwrite the connection description's agreedCompressor programmatically.","Prefer 'zlib' (no native deps) when unsure."],"tags":["compression","wire-protocol","configuration"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}