{"record":{"id":"af20e76d63b5138d","repo":"mongodb/node-mongodb-native","slug":"user-input-for-option-mongodblogcomponentseveriti-af20e7","errorCode":null,"errorMessage":"User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k}","messagePattern":"User input for option 'mongodbLogComponentSeverities' contains invalid key: (.+?)","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/connection_string.ts","lineNumber":1266,"sourceCode":"          `Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable`\n        );\n      }\n      return value;\n    }\n  },\n  mongodbLogComponentSeverities: {\n    transform({ values: [value] }) {\n      if (typeof value !== 'object' || !value) {\n        throw new MongoAPIError(`Option 'mongodbLogComponentSeverities' must be a non-null object`);\n      }\n      for (const [k, v] of Object.entries(value)) {\n        if (typeof v !== 'string' || typeof k !== 'string') {\n          throw new MongoAPIError(\n            `User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value`\n          );\n        }\n        if (!Object.values(MongoLoggableComponent).some(val => val === k) && k !== 'default') {\n          throw new MongoAPIError(\n            `User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k}`\n          );\n        }\n        if (!Object.values(SeverityLevel).some(val => val === v)) {\n          throw new MongoAPIError(\n            `Option 'mongodbLogComponentSeverities' does not support ${v} as a value for ${k}`\n          );\n        }\n      }\n      return value;\n    }\n  },\n  mongodbLogMaxDocumentLength: { type: 'uint' },\n  // Custom types for modifying core behavior\n  connectionType: { type: 'any' },\n  srvPoller: { type: 'any' },\n  // Accepted Node.js Options\n  allowPartialTrustChain: { type: 'any' },","sourceCodeStart":1248,"sourceCodeEnd":1284,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/connection_string.ts#L1248-L1284","documentation":"Each key in `mongodbLogComponentSeverities` must be a recognized component. At src/connection_string.ts:1265 the driver checks `Object.values(MongoLoggableComponent).some(val => val === k) || k === 'default'`. The valid components (frozen at src/mongo_logger.ts:139) are `command`, `topology`, `serverSelection`, `connection`, `client`, plus the special `default`. Any other key throws MongoAPIError at src/connection_string.ts:1266.","triggerScenarios":"Passing `{ query: 'debug' }`, `{ server: 'info' }`, `{ replication: 'warn' }`, or `{ Command: 'debug' }` (case mismatch).","commonSituations":"Inventing component names from server-side logging vocab; using the enum's TypeScript identifier (e.g. `COMMAND`) instead of its value (`command`); typos.","solutions":["Use only: command, topology, serverSelection, connection, client, or default.","Remember keys are the enum VALUES (lowercase camelCase), not the TypeScript constant names.","Use `default` as the catch-all key."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: { query: 'debug' } });\n\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 'debug' } });","handlingStrategy":"validation","validationCode":"import { MongoLoggableComponent } from 'mongodb';\nconst KEYS = [...Object.values(MongoLoggableComponent), 'default'];\nif (opts.mongodbLogComponentSeverities) {\n  for (const k of Object.keys(opts.mongodbLogComponentSeverities)) {\n    if (!KEYS.includes(k)) throw new Error(`invalid component key: ${k}`);\n  }\n}","typeGuard":"function isComponentKey(v: string): boolean { return [...Object.values(MongoLoggableComponent), 'default'].includes(v as any); }","tryCatchPattern":"try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoAPIError && /invalid key/.test(e.message)) { /* drop unknown keys, retry */ } else throw e; }","preventionTips":["Use enum VALUES (command, topology, serverSelection, connection, client), not the constant NAMES.","Use `default` as the catch-all.","Build the allowed-keys list from Object.values(MongoLoggableComponent)."],"tags":["logging","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}