Automattic/mongoose · error · MongooseError

encryptionType must be provided

Error message

encryptionType must be provided

What it means

Error "encryptionType must be provided" thrown in Automattic/mongoose.

Source

Thrown at lib/schema.js:928

      }
    }

    if (val.instanceOfSchema && val.encryptionType() != null) {
      // schema.add({ field: <instance of encrypted schema> })
      if (this.encryptionType() != val.encryptionType()) {
        throw new MongooseError('encryptionType of a nested schema must match the encryption type of the parent schema.');
      }

      for (const [encryptedField, encryptedFieldConfig] of Object.entries(val.encryptedFields)) {
        const path = fullPath + '.' + encryptedField;
        this._addEncryptedField(path, encryptedFieldConfig);
      }
    } else if (typeof val === 'object' && 'encrypt' in val) {
      // schema.add({ field: { type: <schema type>, encrypt: { ... }}})
      const { encrypt } = val;

      if (this.encryptionType() == null) {
        throw new MongooseError('encryptionType must be provided');
      }

      this._addEncryptedField(fullPath, encrypt);
    } else {
      // if the field was already encrypted and we re-configure it to be unencrypted, remove
      // the encrypted field configuration
      this._removeEncryptedField(fullPath);
    }
  }

  const aliasObj = Object.fromEntries(
    Object.entries(obj).map(([key]) => ([prefix + key, null]))
  );
  aliasFields(this, aliasObj);
  return this;
};

/**

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/schema.js:928 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/1cbf6dbcb46314f7. Report an issue: GitHub.