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

  1. Use only tls (preferred) and remove ssl.
  2. 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

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

Related errors


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 setting

View on GitHub (pinned to dce7939f86)