mongodb/node-mongodb-native · error · MongoParseError
Cannot make WriteConcern from wtimeout
Error message
Cannot make WriteConcern from wtimeout
What it means
`wtimeout` (deprecated; use `wtimeoutMS`) routes through `WriteConcern.fromOptions` (src/connection_string.ts:1205-1217); if that returns null the transform throws 'Cannot make WriteConcern from wtimeout'. The same message is reused for the `wtimeoutMS` option at src/connection_string.ts:1229. Generally requires a malformed combination, e.g. a timeout with no valid `w`.
Source
Thrown at src/connection_string.ts:1216
}
});
}
throw new MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`);
}
},
wtimeout: {
deprecated: 'Please use wtimeoutMS instead',
target: 'writeConcern',
transform({ values: [value], options }) {
const wc = WriteConcern.fromOptions({
writeConcern: {
...options.writeConcern,
wtimeout: getUIntFromOptions('wtimeout', value)
}
});
if (wc) return wc;
throw new MongoParseError(`Cannot make WriteConcern from wtimeout`);
}
} as OptionDescriptor,
wtimeoutMS: {
target: 'writeConcern',
transform({ values: [value], options }) {
const wc = WriteConcern.fromOptions({
writeConcern: {
...options.writeConcern,
wtimeoutMS: getUIntFromOptions('wtimeoutMS', value)
}
});
if (wc) return wc;
throw new MongoParseError(`Cannot make WriteConcern from wtimeout`);
}
},
zlibCompressionLevel: {
default: 0,
type: 'int'View on GitHub (pinned to 3366c21a63)
Solutions
- Switch to `wtimeoutMS` (wtimeout is deprecated)
- Pair wtimeoutMS with a `w` value: `{ w: 'majority', wtimeoutMS: 1000 }`
- Remove wtimeout if a timeout is not needed
Example fix
// before
new MongoClient(uri, { wtimeout: 1000 });
// after
new MongoClient(uri, { writeConcern: { w: 'majority', wtimeoutMS: 1000 } }); Defensive patterns
Strategy: validation
Validate before calling
// wtimeout is deprecated; normalize to wtimeoutMS paired with w.
if ('wtimeout' in options) {
const { wtimeout, ...rest } = options;
options = { ...rest, writeConcern: { ...(rest.writeConcern || {}), wtimeoutMS: wtimeout } };
} Try / catch
try {
const client = new MongoClient(uri, options);
} catch (e) {
if (e instanceof MongoParseError && /WriteConcern from wtimeout/.test(e.message)) {
// replace wtimeout with wtimeoutMS and a valid w, then retry
} else throw e;
} Prevention
- Use wtimeoutMS, not the deprecated wtimeout
- Always pair a timeout with a valid w (e.g. 'majority')
- Express write concern as a single writeConcern object
When it happens
Trigger: Providing `wtimeout`/`wtimeoutMS` without a valid `w`; values that yield an empty/invalid write concern after merging.
Common situations: Setting only wtimeout without w; legacy configs that still use the deprecated `wtimeout`; copy-paste from old tutorials.
Related errors
- Unable to make a writeConcern from fsync=${value}
- Unable to make a writeConcern from journal=${value}
- Invalid WriteConcern cannot parse: ${JSON.stringify(value)}
- Cannot set both proxyOptions and kmsConnectCallback
- Can only provide a custom AWS credential provider when the s
AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04).
Data as JSON: /data/errors/96e7c2d537f746b5.json.
Report an issue: GitHub.