mongodb/node-mongodb-native · error · MongoParseError
Expected to be stringified int value, got
Error message
Expected ${name} to be stringified int value, got: ${value} What it means
Integer URI options (e.g. srvMaxHosts, serverSelectionTimeoutMS, connectTimeoutMS) must parse as an integer. getIntFromOptions calls parseInteger; if it returns null (non-numeric, empty, or fractional), this error is thrown with the offending value.
Solutions
- Provide a bare integer number of milliseconds (or the option's documented unit) with no suffix.
- Double-check the option name's expected unit in the driver docs.
Example fix
// before
new MongoClient('mongodb://h/db?connectTimeoutMS=30s');
// after
new MongoClient('mongodb://h/db?connectTimeoutMS=30000'); Defensive patterns
Strategy: validation
Validate before calling
function assertIntOption(name: string, value: unknown) {
if (!/^[-+]?\d+$/.test(String(value))) {
throw new Error(`${name} must be an integer, got: ${value}`);
}
} Type guard
function isStringifiedInt(v: unknown): v is string | number {
return /^[-+]?\d+$/.test(String(v));
} Prevention
- Omit unit suffixes from URI options; use raw milliseconds.
- Build a wrapper that converts typed config objects to validated URIs.
When it happens
Trigger: Supplying a non-integer value to an int option in the URI, e.g. 'srvMaxHosts=three', 'connectTimeoutMS=30s', or 'serverSelectionTimeoutMS=12.5'.
Common situations: Unit suffixes ('30s', '5ms') that the driver does not parse, locale-specific formatting, or copy-pasting human-readable durations from docs.
Related errors
- Cannot have undefined values in key value pairs
- can only be a positive int value, got
- must be either "true" or "false
- All values of tls/ssl must be the same.
- Auth mechanism property ALLOWED_HOSTS is not allowed in the…
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/b65a76ca667f2843.
Report an issue: GitHub.
Appendix: source
Thrown at src/connection_string.ts:193
}
function getBoolean(name: string, value: unknown): boolean {
if (typeof value === 'boolean') return value;
switch (value) {
case 'true':
return true;
case 'false':
return false;
default:
throw new MongoParseError(`${name} must be either "true" or "false"`);
}
}
function getIntFromOptions(name: string, value: unknown): number {
const parsedInt = parseInteger(value);
if (parsedInt != null) {
return parsedInt;
}
throw new MongoParseError(`Expected ${name} to be stringified int value, got: ${value}`);
}
function getUIntFromOptions(name: string, value: unknown): number {
const parsedValue = getIntFromOptions(name, value);
if (parsedValue < 0) {
throw new MongoParseError(`${name} can only be a positive int value, got: ${value}`);
}
return parsedValue;
}
function* entriesFromString(value: string): Generator<[string, string]> {
if (value === '') {
return;
}
const keyValuePairs = value.split(',');
for (const keyValue of keyValuePairs) {
const [key, value] = keyValue.split(/:(.*)/);
if (value == null) {View on GitHub (pinned to dce7939f86)