Automattic/mongoose · error · Error
Discriminator "${name}" cannot have field with name "${key}"
Error message
Discriminator "${name}" cannot have field with name "${key}" What it means
Error "Discriminator "${name}" cannot have field with name "${key}"" thrown in Automattic/mongoose.
Source
Thrown at lib/helpers/model/discriminator.js:120
existingPath.options.$skipDiscriminatorCheck = true;
} else {
const baseSchemaAddition = {};
baseSchemaAddition[key] = {
default: void 0,
select: true,
$skipDiscriminatorCheck: true
};
baseSchemaAddition[key][model.schema.options.typeKey] = String;
model.schema.add(baseSchemaAddition);
defineKey({
prop: key,
prototype: model.prototype,
options: model.schema.options
});
}
if (schema.path(key) && schema.path(key).options.$skipDiscriminatorCheck !== true) {
throw new Error('Discriminator "' + name +
'" cannot have field with name "' + key + '"');
}
let value = name;
if ((typeof tiedValue === 'string' && tiedValue.length) || tiedValue != null) {
value = tiedValue;
}
validateDiscriminatorSchemasForEncryption(model.schema, schema);
function merge(schema, baseSchema) {
// Retain original schema before merging base schema
schema._baseSchema = baseSchema;
if (baseSchema.paths._id &&
baseSchema.paths._id.options &&
!baseSchema.paths._id.options.auto) {
schema.remove('_id');
}View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/helpers/model/discriminator.js:120 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/e3add2a2fc154641.
Report an issue: GitHub.