mongodb/node-mongodb-native · error · MongoAPIError
User input for option 'mongodbLogComponentSeverities' contai
Error message
User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k} What it means
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.
Source
Thrown at src/connection_string.ts:1266
`Option 'mongodbLogPath' must be of type 'stderr' | 'stdout' | MongoDBLogWritable`
);
}
return value;
}
},
mongodbLogComponentSeverities: {
transform({ values: [value] }) {
if (typeof value !== 'object' || !value) {
throw new MongoAPIError(`Option 'mongodbLogComponentSeverities' must be a non-null object`);
}
for (const [k, v] of Object.entries(value)) {
if (typeof v !== 'string' || typeof k !== 'string') {
throw new MongoAPIError(
`User input for option 'mongodbLogComponentSeverities' object cannot include a non-string key or value`
);
}
if (!Object.values(MongoLoggableComponent).some(val => val === k) && k !== 'default') {
throw new MongoAPIError(
`User input for option 'mongodbLogComponentSeverities' contains invalid key: ${k}`
);
}
if (!Object.values(SeverityLevel).some(val => val === v)) {
throw new MongoAPIError(
`Option 'mongodbLogComponentSeverities' does not support ${v} as a value for ${k}`
);
}
}
return value;
}
},
mongodbLogMaxDocumentLength: { type: 'uint' },
// Custom types for modifying core behavior
connectionType: { type: 'any' },
srvPoller: { type: 'any' },
// Accepted Node.js Options
allowPartialTrustChain: { type: 'any' },View on GitHub (pinned to 3366c21a63)
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.
Example fix
// before
new MongoClient(uri, { mongodbLogComponentSeverities: { commands: 'debug' } }); // typo
// after
new MongoClient(uri, { mongodbLogComponentSeverities: { command: 'debug' } }); Defensive patterns
Strategy: validation
Validate before calling
import { MongoLoggableComponent } from 'mongodb';
const VALID = new Set([...Object.values(MongoLoggableComponent), 'default']);
function validKeys(o) { return Object.keys(o).every(k => VALID.has(k)); } Type guard
function isValidComponentKey(k): k is string {
return Object.values(MongoLoggableComponent).includes(k as any) || k === 'default';
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Guessing component names instead of consulting MongoLoggableComponent; using a name from a different driver/language; pluralization or camelCase mistakes.
Related errors
- Option 'mongodbLogComponentSeverities' does not support ${v}
- Option 'mongodbLogPath' must be of type 'stderr' | 'stdout'
- Option 'mongodbLogComponentSeverities' must be a non-null ob
- User input for option 'mongodbLogComponentSeverities' object
- Descriptors missing a type must define a transform
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/af20e76d63b5138d.json.
Report an issue: GitHub.