Automattic/mongoose · error · MongooseError
Cannot set nested path `${path}`. Parent path `${fullPath}`
Error message
Cannot set nested path `${path}`. Parent path `${fullPath}` already set to type ${branch[sub].name}. What it means
Error "Cannot set nested path `${path}`. Parent path `${fullPath}` already set to type ${branch[sub].name}." thrown in Automattic/mongoose.
Source
Thrown at lib/schema.js:1342
let branch = this.tree;
let fullPath = '';
for (const sub of subpaths) {
if (utils.specialProperties.has(sub)) {
throw new MongooseError('Cannot set special property `' + sub + '` on a schema');
}
fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;
if (!branch[sub]) {
this.nested[fullPath] = true;
branch[sub] = {};
}
if (typeof branch[sub] !== 'object') {
const msg = 'Cannot set nested path `' + path + '`. '
+ 'Parent path `'
+ fullPath
+ '` already set to type ' + branch[sub].name
+ '.';
throw new MongooseError(msg);
}
branch = branch[sub];
}
branch[last] = clone(obj);
this.paths[path] = this.interpretAsType(path, obj, this.options);
const schemaType = this.paths[path];
// If overwriting an existing path, make sure to clear the childSchemas
this.childSchemas = this.childSchemas.filter(childSchema => childSchema.path !== path);
if (schemaType.$isSchemaMap) {
// Maps can have arbitrary keys, so `$*` is internal shorthand for "any key"
// The '$' is to imply this path should never be stored in MongoDB so we
// can easily build a regexp out of this path, and '*' to imply "any key."
const mapPath = path + '.$*';
View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/schema.js:1342 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/83fb3063a40c853c.
Report an issue: GitHub.