Automattic/mongoose · error · MongooseError

`versionKey` must be falsy or string, got `${typeof options.

Error message

`versionKey` must be falsy or string, got `${typeof options.versionKey}`

What it means

Error "`versionKey` must be falsy or string, got `${typeof options.versionKey}`" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:641

    discriminatorKey: '__t',
    shardKey: null,
    read: null,
    validateBeforeSave: true,
    validateModifiedOnly: false,
    // the following are only applied at construction time
    _id: true,
    id: defaultId,
    typeKey: 'type',
    ...options
  };

  // Treat `undefined` as "not provided" for these options
  options.strict ??= defaultStrict;
  options.strictQuery ??= defaultStrictQuery;
  options.id ??= defaultId;

  if (options.versionKey && typeof options.versionKey !== 'string') {
    throw new MongooseError('`versionKey` must be falsy or string, got `' + (typeof options.versionKey) + '`');
  }

  if (typeof options.read === 'string') {
    options.read = handleReadPreferenceAliases(options.read);
  } else if (Array.isArray(options.read) && typeof options.read[0] === 'string') {
    options.read = {
      mode: handleReadPreferenceAliases(options.read[0]),
      tags: options.read[1]
    };
  }

  if (options.optimisticConcurrency && !options.versionKey) {
    throw new MongooseError('Must set `versionKey` if using `optimisticConcurrency`');
  }

  return options;
};

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:641 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/82f635f07d7006f8. Report an issue: GitHub.