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

  1. Switch to `wtimeoutMS` (wtimeout is deprecated)
  2. Pair wtimeoutMS with a `w` value: `{ w: 'majority', wtimeoutMS: 1000 }`
  3. 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

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


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