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

Thrown when the driver resolves all `tls` and `ssl` values (from both URI query params and the options object) and finds inconsistent booleans. Because tls and ssl are aliases, mixing true/false across them is ambiguous and rejected. The check at connection_string.ts:355 builds a Set of resolved boolean values; size !== 1 means conflict.

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 3366c21a63)

Solutions

  1. Pick one option name (prefer tls) and use it consistently across URI and options object.
  2. Remove either the tls or ssl entry so only one resolved boolean remains.
  3. If you need TLS off, set tls=false everywhere consistently (and avoid ssl entirely).

Example fix

// before
const c = new MongoClient('mongodb://host:27017/?tls=true', { ssl: false });
// after
const c = new MongoClient('mongodb://host:27017/?tls=false');
Defensive patterns

Strategy: validation

Validate before calling

const hasTLS = new URL(uri).searchParams.has('tls');
const hasSSL = new URL(uri).searchParams.has('ssl');
if ((hasTLS || 'tls' in opts) && (hasSSL || 'ssl' in opts)) {
  throw new Error('Specify only tls OR ssl, not both');
}

Prevention

When it happens

Trigger: Passing URI '?tls=true' with options { ssl: false }, or '?ssl=false' with { tls: true }, or '?tls=true&ssl=false' in the same URI. Any combination resolving to conflicting booleans triggers it.

Common situations: Migrating from deprecated ssl to tls without removing the old flag; environment-specific config that toggles ssl in code while a base URI hardcodes tls; templated URIs that append tls unconditionally.

Related errors


AI-assisted analysis of mongodb/node-mongodb-native@3366c21a63 (2026-08-04). Data as JSON: /data/errors/816b63ab10fab843.json. Report an issue: GitHub.