Automattic/mongoose · error · Error
encrypted fields cannot have the same path as a non-encrypte
Error message
encrypted fields cannot have the same path as a non-encrypted field for discriminators. path=${path} What it means
Error "encrypted fields cannot have the same path as a non-encrypted field for discriminators. path=${path}" thrown in Automattic/mongoose.
Source
Thrown at lib/helpers/model/discriminator.js:44
*
* @param {Schema} parentSchema
* @param {Schema} childSchema
*/
function validateDiscriminatorSchemasForEncryption(parentSchema, childSchema) {
if (parentSchema.encryptionType() == null && childSchema.encryptionType() == null) return;
const allSharedNestedPaths = setIntersection(
allNestedPaths(parentSchema),
allNestedPaths(childSchema)
);
for (const path of allSharedNestedPaths) {
if (parentSchema._hasEncryptedField(path) && childSchema._hasEncryptedField(path)) {
throw new Error(`encrypted fields cannot be declared on both the base schema and the child schema in a discriminator. path=${path}`);
}
if (parentSchema._hasEncryptedField(path) || childSchema._hasEncryptedField(path)) {
throw new Error(`encrypted fields cannot have the same path as a non-encrypted field for discriminators. path=${path}`);
}
}
function allNestedPaths(schema) {
return [...Object.keys(schema.paths), ...Object.keys(schema.singleNestedPaths)];
}
/**
* @param {Iterable<string>} i1
* @param {Iterable<string>} i2
*/
function* setIntersection(i1, i2) {
const s1 = new Set(i1);
for (const item of i2) {
if (s1.has(item)) {
yield item;
}
}View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/helpers/model/discriminator.js:44 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/347ae85163690586.
Report an issue: GitHub.