Automattic/mongoose · error · MongooseError

invalid `encryptionType`: ${encryptionType}

Error message

invalid `encryptionType`: ${encryptionType}

What it means

Error "invalid `encryptionType`: ${encryptionType}" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:757

  const defaultOptions = Object.assign({}, baseOptions, schemaOptions);

  this._defaultToObjectOptionsMap = this._defaultToObjectOptionsMap || {};
  this._defaultToObjectOptionsMap[path] = utils.hasOwnKeys(defaultOptions) ? defaultOptions : null;
  return defaultOptions;
};

/**
 * Sets the encryption type of the schema, if a value is provided, otherwise
 * returns the encryption type.
 *
 * @param {'csfle' | 'queryableEncryption' | null | undefined} encryptionType plain object with paths to add, or another schema
 */
Schema.prototype.encryptionType = function encryptionType(encryptionType) {
  if (arguments.length === 0) {
    return this.options.encryptionType;
  }
  if (!(typeof encryptionType === 'string' || encryptionType === null)) {
    throw new MongooseError(`invalid \`encryptionType\`: ${encryptionType}`);
  }
  this.options.encryptionType = encryptionType;
};

/**
 * Adds key path / schema type pairs to this schema.
 *
 * #### Example:
 *
 *     const ToySchema = new Schema();
 *     ToySchema.add({ name: 'string', color: 'string', price: 'number' });
 *
 *     const TurboManSchema = new Schema();
 *     // You can also `add()` another schema and copy over all paths, virtuals,
 *     // getters, setters, indexes, methods, and statics.
 *     TurboManSchema.add(ToySchema).add({ year: Number });
 *
 * @param {object|Schema} obj plain object with paths to add, or another schema

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:757 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/23aebbd5a0866b15. Report an issue: GitHub.