{"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/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/connection_string.ts#L1248-L1284","documentation":"Thrown when a key in mongodbLogComponentSeverities is not a member of the MongoLoggableComponent enum and is not the literal 'default'. The driver enumerates known components (command, connection, serverSelection, etc.) and rejects unknown names.","triggerScenarios":"Passing { commands: 'debug' } (plural, typo), { cmd: 'debug' }, { replicaSet: 'info' } (wrong casing/spelling), or any invented component name. The check compares against Object.values(MongoLoggableComponent) plus the special 'default' key.","commonSituations":"Guessing component names instead of consulting MongoLoggableComponent; using a name from a different driver/language; pluralization or camelCase mistakes.","solutions":["Use only keys from the MongoLoggableComponent enum (importable from the driver) or the reserved 'default'.","Common valid keys: 'command', 'connection', 'serverSelection', 'topology', 'serverHeartbeat', 'mongoLog', 'default'.","Use 'default' for a catch-all severity instead of guessing component names."],"exampleFix":"// before\nnew MongoClient(uri, { mongodbLogComponentSeverities: { commands: 'debug' } }); // typo\n// after\nnew MongoClient(uri, { mongodbLogComponentSeverities: { command: 'debug' } });","handlingStrategy":"validation","validationCode":"import { MongoLoggableComponent } from 'mongodb';\nconst VALID = new Set([...Object.values(MongoLoggableComponent), 'default']);\nfunction validKeys(o) { return Object.keys(o).every(k => VALID.has(k)); }","typeGuard":"function isValidComponentKey(k): k is string {\n  return Object.values(MongoLoggableComponent).includes(k as any) || k === 'default';\n}","tryCatchPattern":null,"preventionTips":["Import MongoLoggableComponent and derive the allowed key set rather than hardcoding.","Use 'default' as the catch-all instead of guessing component names.","Cross-check component names against the driver version you target."],"tags":["logging","options","configuration","enum-validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}