{"record":{"id":"83fb3063a40c853c","repo":"Automattic/mongoose","slug":"cannot-set-nested-path-path-parent-path-f","errorCode":null,"errorMessage":"Cannot set nested path `${path}`. Parent path `${fullPath}` already set to type ${branch[sub].name}.","messagePattern":"Cannot set nested path `(.+?)`\\. Parent path `(.+?)` already set to type (.+?)\\.","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/schema.js","lineNumber":1342,"sourceCode":"  let branch = this.tree;\n  let fullPath = '';\n\n  for (const sub of subpaths) {\n    if (utils.specialProperties.has(sub)) {\n      throw new MongooseError('Cannot set special property `' + sub + '` on a schema');\n    }\n    fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;\n    if (!branch[sub]) {\n      this.nested[fullPath] = true;\n      branch[sub] = {};\n    }\n    if (typeof branch[sub] !== 'object') {\n      const msg = 'Cannot set nested path `' + path + '`. '\n          + 'Parent path `'\n          + fullPath\n          + '` already set to type ' + branch[sub].name\n          + '.';\n      throw new MongooseError(msg);\n    }\n    branch = branch[sub];\n  }\n\n  branch[last] = clone(obj);\n\n  this.paths[path] = this.interpretAsType(path, obj, this.options);\n  const schemaType = this.paths[path];\n\n  // If overwriting an existing path, make sure to clear the childSchemas\n  this.childSchemas = this.childSchemas.filter(childSchema => childSchema.path !== path);\n\n  if (schemaType.$isSchemaMap) {\n    // Maps can have arbitrary keys, so `$*` is internal shorthand for \"any key\"\n    // The '$' is to imply this path should never be stored in MongoDB so we\n    // can easily build a regexp out of this path, and '*' to imply \"any key.\"\n    const mapPath = path + '.$*';\n","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/schema.js#L1324-L1360","documentation":"Error \"Cannot set nested path `${path}`. Parent path `${fullPath}` already set to type ${branch[sub].name}.\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/schema.js:1342 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}