{"record":{"id":"3678ebdac819fcb2","repo":"Automattic/mongoose","slug":"no-populated-model-found-for-path-this-arraypat","errorCode":null,"errorMessage":"No populated model found for path `${this[arrayPathSymbol]}`. This is likely a bug in Mongoose, please report an issue on github.com/Automattic/mongoose.","messagePattern":"No populated model found for path `(.+?)`\\. This is likely a bug in Mongoose, please report an issue on github\\.com/Automattic/mongoose\\.","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/types/array/methods/index.js","lineNumber":268,"sourceCode":"   * @method _cast\n   * @api private\n   * @memberOf MongooseArray\n   */\n\n  _cast(value) {\n    let populated = false;\n    let Model;\n\n    const parent = this[arrayParentSymbol];\n    if (parent) {\n      populated = parent.$populated(this[arrayPathSymbol], true);\n    }\n\n    if (populated && value != null) {\n      // cast to the populated Models schema\n      Model = populated.options[populateModelSymbol];\n      if (Model == null) {\n        throw new MongooseError('No populated model found for path `' + this[arrayPathSymbol] + '`. This is likely a bug in Mongoose, please report an issue on github.com/Automattic/mongoose.');\n      }\n\n      // only objects are permitted so we can safely assume that\n      // non-objects are to be interpreted as _id\n      if (Buffer.isBuffer(value) ||\n          isBsonType(value, 'ObjectId') || !utils.isObject(value)) {\n        value = { _id: value };\n      }\n\n      // gh-2399\n      // we should cast model only when it's not a discriminator\n      const isDisc = value.schema?.discriminatorMapping?.key !== undefined;\n      if (!isDisc) {\n        value = new Model(value);\n      }\n      return this[arraySchemaSymbol].embeddedSchemaType.applySetters(value, parent, true);\n    }\n","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/types/array/methods/index.js#L250-L286","documentation":"Internal invariant in MongooseArray._cast(): the array's path reports itself as populated, but the populate metadata's options[populateModelSymbol] is null, so Mongoose cannot determine which model to cast the pushed value to. Mongoose itself labels this 'likely a bug' — the populated state is inconsistent rather than a user input problem.","triggerScenarios":"Calling doc.populatedArr.push(value) or doc.populatedArr[i] = value when the populate metadata lacks the internal model symbol — after manual $populated manipulation, populate() with a refPath that resolves to a missing model, or an actual Mongoose regression.","commonSituations":"Appearing after upgrading Mongoose versions; using refPath with discriminators; code that manually crafts populated state or reuses populate options objects across documents.","solutions":["Upgrade to the latest Mongoose patch release — this guard exists for real fixed bugs","If it reproduces on the latest version, file an issue at github.com/Automaltic/mongoose with a minimal repro","As a workaround, replace the whole array instead of pushing into a populated one: doc.arr = [...doc.arr.filter(x => cond), newItem]","Check that ref/refPath on the path always resolves to a registered model"],"exampleFix":"// before\ndoc.populatedArr.push(newItem); // internal model symbol missing\n// after (workaround)\ndoc.populatedArr = doc.populatedArr.concat([newItem]);","handlingStrategy":"try-catch","validationCode":"const POPULATE_MODEL = require('mongoose').populateModelSymbol ?? null; // internal\nfunction canPushIntoPopulated(doc, path) {\n  const pop = doc.$populated && doc.$populated(path, true);\n  return !pop || (pop.options && pop.options.model != null);\n}","typeGuard":"function isSafeToPush(doc, path) { const pop = doc.$populated?.(path, true); return pop == null || pop.options?.model != null; }","tryCatchPattern":"try { doc.arr.push(item); } catch (err) { if (/No populated model found/.test(err.message)) { doc.arr = doc.arr.concat([item]); reportUpstream(err, doc); } else throw err; }","preventionTips":["Pin and regularly upgrade Mongoose versions; regression-test populate flows after upgrades","Avoid pushing into populated arrays — reassign the whole array","Ensure every ref/refPath resolves to a registered model before populate"],"tags":["mongoose","populate","array","internal-bug"],"backgroundTag":"internal-library-bug","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}