{"record":{"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/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L775-L811","documentation":"After accepting the compressors value, the transform iterates each entry and checks `Object.keys(Compressor).includes(String(c))` at src/connection_string.ts:790. The Compressor object is frozen at src/cmap/wire_protocol/compression.ts:18 with keys `none`, `snappy`, `zlib`, `zstd`. Any entry that is not one of those names triggers MongoInvalidArgumentError at src/connection_string.ts:793 with a message listing the valid keys.","triggerScenarios":"Passing `compressors: ['gzip']`, `compressors: ['lz4']`, `compressors: 'brotli'`, or `?compressors=gzip` in the URI. The check runs per-entry, so the offending name is interpolated into the message.","commonSituations":"Confusing MongoDB wire-protocol compressors with HTTP content-encoding names; typos like 'z-lib' or 'snappy4'; assuming a system-installed codec name is accepted. Note `snappy` and `zstd` are optional peer dependencies and must also be installed, but a missing dependency surfaces as a different error — this error is purely about the name.","solutions":["Use only one of: `none`, `snappy`, `zlib`, `zstd`.","If you need `snappy` or `zstd`, also install the optional package (`snappy`, `@mongodb-js/zstd`).","Spell the name exactly as in the Compressor object (lowercase, no hyphens)."],"exampleFix":"// before\nnew MongoClient(uri, { compressors: ['gzip'] });\n\n// after\nnew MongoClient(uri, { compressors: ['zlib'] });","handlingStrategy":"validation","validationCode":"import { Compressor } from 'mongodb';\nconst VALID = Object.keys(Compressor); // ['none','snappy','zlib','zstd']\nconst list = typeof opts.compressors === 'string' ? opts.compressors.split(',') : (opts.compressors as any[] ?? []);\nfor (const c of list) {\n  if (!VALID.includes(String(c))) throw new Error(`invalid compressor: ${c}`);\n}","typeGuard":"function isCompressorName(v: unknown, valid: string[]): v is string { return typeof v === 'string' && valid.includes(v); }","tryCatchPattern":"try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoInvalidArgumentError && /compression mechanism/.test(e.message)) { /* remove the bad name */ } else throw e; }","preventionTips":["Restrict the compressor list to a constant derived from Object.keys(Compressor).","Install optional deps (snappy, @mongodb-js/zstd) when you reference them.","Avoid 'none' in the array — it disables compression by name."],"tags":["connection-options","compression","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}