{"id":"d531a127138abcd6","repo":"mongodb/node-mongodb-native","slug":"compressors-must-be-an-array-or-a-comma-delimited","errorCode":null,"errorMessage":"compressors must be an array or a comma-delimited list of strings","messagePattern":"compressors must be an array or a comma-delimited list of strings","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":785,"sourceCode":"            ServerApiVersion\n          ).join('\", \"')}\"]`\n        );\n      }\n      return serverApiToValidate;\n    }\n  },\n  checkKeys: {\n    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  },","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L767-L803","documentation":"The `compressors` option accepts an array of compressor names or a single comma-delimited string. The transform (src/connection_string.ts:777-802) splits strings on commas; if a value is neither a string nor an array, it throws a MongoInvalidArgumentError.","triggerScenarios":"`{ compressors: 1 }`; `{ compressors: true }`; `{ compressors: { name: 'zstd' } }`; `{ compressors: null }`.","commonSituations":"Passing a single compressor as a non-string scalar; config-merge bugs producing the wrong type; JSON typed as number/boolean.","solutions":["Pass compressors as an array: ['zstd', 'snappy']","Or a comma-delimited string: 'zstd,snappy'","Omit the option to use the default 'none'"],"exampleFix":"// before\nnew MongoClient(uri, { compressors: 1 });\n// after\nnew MongoClient(uri, { compressors: ['zstd', 'snappy'] });","handlingStrategy":"validation","validationCode":"function isCompressorsInput(v) {\n  return typeof v === 'string' || Array.isArray(v);\n}\nif (options.compressors != null && !isCompressorsInput(options.compressors)) {\n  throw new TypeError('compressors must be an array or comma-delimited string');\n}","typeGuard":"function isCompressorsInput(v) {\n  return typeof v === 'string' || Array.isArray(v);\n}","tryCatchPattern":null,"preventionTips":["Pass compressors as an array of strings","Validate the type before constructing the client when config is dynamic","Omit the option to keep the default 'none'"],"tags":["configuration","compression","options"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}