mongodb/node-mongodb-native · error · MongoParseError
All values of tls/ssl must be the same.
Error message
All values of tls/ssl must be the same.
What it means
tls and ssl are aliases that must agree. The driver collects every value of tls and ssl (from both URI and options), coerces each through getBoolean, and requires the resulting set to have exactly one element. Conflicting values (e.g. tls=true with ssl=false) are rejected.
Solutions
- Use only tls (preferred) and remove ssl.
- If both must appear, ensure they resolve to the same boolean.
Example fix
// before 'mongodb://h/db?tls=true&ssl=false' // after 'mongodb://h/db?tls=true'
Defensive patterns
Strategy: validation
Validate before calling
function assertTlsSslAgree(uri: string, opts: Record<string, unknown> = {}) {
const vals: boolean[] = [];
const q = new URLSearchParams(uri.split('?')[1] ?? '');
for (const k of ['tls', 'ssl']) {
if (q.has(k)) vals.push(q.get(k) === 'true');
if (opts[k] != null) vals.push(Boolean(opts[k]));
}
if (new Set(vals).size > 1) throw new Error('All tls/ssl values must agree');
} Prevention
- Standardize on 'tls' and remove all 'ssl' usage.
- Avoid setting TLS both in the URI and in the options object.
When it happens
Trigger: A URI like 'mongodb://h/db?tls=true&ssl=false', or combining { tls: true } in options with 'ssl=false' in the URI, or 'tls=true&tls=false'.
Common situations: Migrating from ssl to tls terminology and leaving both set, or merging config layers (env var + code) that disagree.
Understand the failure class
- SSL/TLS and certificate errors — how TLS handshakes and certificate validation fail.
Related errors
- The ' ' option cannot be used with the ' ' option
- Auth mechanism property ALLOWED_HOSTS is not allowed in the…
- authMechanism requires an authSource of '$external
- Cannot combine replicaSet option with srvMaxHosts
- Cannot have empty URI params in DNS TXT Record
AI-assisted analysis of mongodb/node-mongodb-native@dce7939f86 (2026-08-11).
Data as JSON: /api/errors/816b63ab10fab843.
Report an issue: GitHub.
Appendix: source
Thrown at src/connection_string.ts:356
for (const key of allProvidedKeys) {
const values = [];
const objectOptionValue = objectOptions.get(key);
if (objectOptionValue != null) {
values.push(objectOptionValue);
}
const urlValues = urlOptions.get(key) ?? [];
values.push(...urlValues);
allProvidedOptions.set(key, values);
}
if (allProvidedOptions.has('tls') || allProvidedOptions.has('ssl')) {
const tlsAndSslOpts = (allProvidedOptions.get('tls') || [])
.concat(allProvidedOptions.get('ssl') || [])
.map(getBoolean.bind(null, 'tls/ssl'));
if (new Set(tlsAndSslOpts).size !== 1) {
throw new MongoParseError('All values of tls/ssl must be the same.');
}
}
checkTLSOptions(allProvidedOptions);
const unsupportedOptions = setDifference(
allProvidedKeys,
Array.from(Object.keys(OPTIONS)).map(s => s.toLowerCase())
);
if (unsupportedOptions.size !== 0) {
const optionWord = unsupportedOptions.size > 1 ? 'options' : 'option';
const isOrAre = unsupportedOptions.size > 1 ? 'are' : 'is';
throw new MongoParseError(
`${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported`
);
}
// Option parsing and settingView on GitHub (pinned to dce7939f86)