mongodb/node-mongodb-native · warning · MongoParseError
Cannot make WriteConcern from wtimeout
Error message
Cannot make WriteConcern from wtimeout
What it means
`wtimeout` is a deprecated write-concern option (descriptor: `deprecated: 'Please use wtimeoutMS instead'`). The transform at src/connection_string.ts:1208 builds a WriteConcern from `{...options.writeConcern, wtimeout: getUIntFromOptions('wtimeout', value)}`; if fromOptions returns falsy, MongoParseError is thrown at src/connection_string.ts:1216. Non-uint values fail earlier inside getUIntFromOptions.
Solutions
- Use `wtimeoutMS` (the canonical name) instead of `wtimeout`.
- Pair it with a valid `w`, e.g. `writeConcern: { w: 'majority', wtimeoutMS: 1000 }`.
- Audit config merging so `w` is not deleted alongside wtimeout.
Example fix
// before
new MongoClient(uri, { wtimeout: 1000 });
// after
new MongoClient(uri, { writeConcern: { w: 'majority', wtimeoutMS: 1000 } }); Defensive patterns
Strategy: validation
Validate before calling
if ('wtimeout' in (opts as any)) {
console.warn('wtimeout is deprecated; use wtimeoutMS');
const ms = Number((opts as any).wtimeout);
delete (opts as any).wtimeout;
opts.writeConcern = { ...(opts.writeConcern as any), wtimeoutMS: ms };
} Type guard
null
Try / catch
try { client = new MongoClient(uri, opts); } catch (e) { if (e instanceof MongoParseError && /wtimeout/.test(e.message)) { const ms = (opts as any).wtimeout; delete (opts as any).wtimeout; opts.writeConcern = { w: 'majority', wtimeoutMS: ms }; client = new MongoClient(uri, opts); } else throw e; } Prevention
- Migrate config from `wtimeout` to `wtimeoutMS`.
- Always pair the timeout with an explicit `w`.
- Grep the codebase for the deprecated name during upgrades.
When it happens
Trigger: Passing `wtimeout: 1000` while the surrounding writeConcern fields leave fromOptions with nothing valid to build; layering `wtimeout` over a writeConcern object whose `w` field was removed.
Common situations: Carrying forward v3-era option names; config merge layers that strip `w`; using wtimeout without also specifying a replication factor.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Unable to make a writeConcern from fsync=
- Unable to make a writeConcern from journal=
- Invalid WriteConcern cannot parse
- Argument "iterator" must be a function
- 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/96e7c2d537f746b5.
Report an issue: GitHub.
Appendix: 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 dce7939f86)