{"id":"b37101abeacb74e0","repo":"mongodb/node-mongodb-native","slug":"c-is-not-a-valid-compression-mechanism-must-be","errorCode":null,"errorMessage":"${c} is not a valid compression mechanism. Must be one of: ${Object.keys(Compressor)}.","messagePattern":"(.+?) is not a valid compression mechanism\\. Must be one of: (.+?)\\.","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":793,"sourceCode":"    type: 'boolean'\n  },\n  compressors: {\n    default: 'none',\n    target: 'compressors',\n    transform({ values }) {\n      const compressionList = new Set();\n      for (const compVal of values as (CompressorName[] | string)[]) {\n        const compValArray = typeof compVal === 'string' ? compVal.split(',') : compVal;\n        if (!Array.isArray(compValArray)) {\n          throw new MongoInvalidArgumentError(\n            'compressors must be an array or a comma-delimited list of strings'\n          );\n        }\n        for (const c of compValArray) {\n          if (Object.keys(Compressor).includes(String(c))) {\n            compressionList.add(String(c));\n          } else {\n            throw new MongoInvalidArgumentError(\n              `${c} is not a valid compression mechanism. Must be one of: ${Object.keys(\n                Compressor\n              )}.`\n            );\n          }\n        }\n      }\n      return [...compressionList];\n    }\n  },\n  connectTimeoutMS: {\n    default: 30000,\n    type: 'uint'\n  },\n  dbName: {\n    type: 'string'\n  },\n  directConnection: {","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L775-L811","documentation":"Each entry in `compressors` must match a key of the `Compressor` enum: `none`, `snappy`, `zlib`, or `zstd`. An unrecognized name throws a MongoInvalidArgumentError at src/connection_string.ts:793.","triggerScenarios":"`{ compressors: ['gzip'] }` (gzip is invalid — MongoDB uses 'zlib'); `{ compressors: 'brotli' }`; `{ compressors: ['lz4'] }`; `{ compressors: 'snappy,zstd,gzip' }`.","commonSituations":"Assuming MongoDB uses 'gzip' (it uses 'zlib'); listing a compressor whose optional native dependency isn't installed; copy-paste from HTTP compression configs.","solutions":["Use only 'none', 'snappy', 'zlib', or 'zstd'","Replace 'gzip' with 'zlib'","Install the optional native package for the chosen compressor (e.g. mongodb-js/zstd for zstd)"],"exampleFix":"// before\nnew MongoClient(uri, { compressors: ['gzip'] });\n// after\nnew MongoClient(uri, { compressors: ['zlib'] });","handlingStrategy":"validation","validationCode":"import { Compressor } from 'mongodb';\nconst VALID = new Set(Object.keys(Compressor));\nfunction normalizeCompressors(v) {\n  return typeof v === 'string' ? v.split(',') : v;\n}\nfunction allValid(v) {\n  return normalizeCompressors(v).every(c => VALID.has(String(c)));\n}\nif (options.compressors && !allValid(options.compressors)) {\n  throw new TypeError('compressors contains an invalid mechanism');\n}","typeGuard":"import { Compressor } from 'mongodb';\nfunction isValidCompressorName(c) {\n  return Object.keys(Compressor).includes(String(c));\n}","tryCatchPattern":null,"preventionTips":["Use only 'none', 'snappy', 'zlib', 'zstd'","Remember MongoDB uses 'zlib', not 'gzip'","Install the native package for the chosen compressor"],"tags":["configuration","compression","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}