mongodb/node-mongodb-native · error · MongoAPIError
Option 'mongodbLogComponentSeverities' does not support
Error message
Option 'mongodbLogComponentSeverities' does not support ${v} as a value for ${k} What it means
Each value in `mongodbLogComponentSeverities` must be a recognized severity. At src/connection_string.ts:1270 the driver checks `Object.values(SeverityLevel).some(val => val === v)`. SeverityLevel (frozen at src/mongo_logger.ts:85) contains: `emergency`, `alert`, `critical`, `error`, `warn`, `notice`, `info`, `debug`, `trace`, `off`. Any other value throws MongoAPIError at src/connection_string.ts:1271.
Solutions
- Use exactly one of: emergency, alert, critical, error, warn, notice, info, debug, trace, off (lowercase).
- Note `warn` — not `warning` — and `info` — not `information`.
- Set a component to `off` to silence it.
Example fix
// before
new MongoClient(uri, { mongodbLogComponentSeverities: { command: 'warning' } });
// after
new MongoClient(uri, { mongodbLogComponentSeverities: { command: 'warn' } }); Defensive patterns
Strategy: validation
Validate before calling
import { SeverityLevel } from 'mongodb';
const VALUES = Object.values(SeverityLevel); // emergency, alert, critical, error, warn, notice, info, debug, trace, off
if (opts.mongodbLogComponentSeverities) {
for (const [k, v] of Object.entries(opts.mongodbLogComponentSeverities as Record<string, string>)) {
if (!VALUES.includes(v as any)) throw new Error(`invalid severity ${v} for ${k}`);
}
} Type guard
function isSeverityValue(v: unknown): boolean { return typeof v === 'string' && Object.values(SeverityLevel).includes(v as any); } Try / catch
try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoAPIError && /does not support/.test(e.message)) { opts.mongodbLogComponentSeverities = { default: 'info' }; client = new MongoClient(uri, opts); } else throw e; } Prevention
- Use `warn` not `warning`, `info` not `information`.
- Build the allowed-values list from Object.values(SeverityLevel).
- Use `off` to silence a component.
When it happens
Trigger: Passing `{ command: 'warning' }` (the canonical name is `warn`, not `warning`); `{ command: 'information' }`; `{ command: 'verbose' }`; `{ command: 'WARNING' }` (case mismatch).
Common situations: Using full-word severity names from other loggers (pino/winston use 'warn' too, but 'warning' is a common typo); using uppercase from RFC 5424; using numeric levels.
Related errors
- Option 'mongodbLogComponentSeverities' must be a non-null…
- Option 'mongodbLogPath' must be of type 'stderr' | 'stdout'…
- User input for option 'mongodbLogComponentSeverities'…
- User input for option 'mongodbLogComponentSeverities'…
- Auth mechanism property ALLOWED_HOSTS must be an array of…
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/d77f4fe6974268ee.
Report an issue: GitHub.
Appendix: source
Thrown at src/connection_string.ts:1271
},
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' },
minDHSize: { type: 'any' },
pskCallback: { type: 'any' },
secureContext: { type: 'any' },
enableTrace: { type: 'any' },
requestCert: { type: 'any' },View on GitHub (pinned to dce7939f86)