{"record":{"id":"48135d80af7d9d79","repo":"Automattic/mongoose","slug":"can-t-populate-individual-element-in-an-array","errorCode":null,"errorMessage":"Can't populate individual element in an array","messagePattern":"Can't populate individual element in an array","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/helpers/populate/modelNamesFromRefPath.js","lineNumber":34,"sourceCode":"\n  if (typeof refPath !== 'string') {\n    throw new MongooseError('`refPath` must be a string or a function that returns a string, got ' + util.inspect(refPath));\n  }\n\n  if (queryProjection != null && isPathExcluded(queryProjection, refPath)) {\n    throw new MongooseError('refPath `' + refPath + '` must not be excluded in projection, got ' +\n      util.inspect(queryProjection));\n  }\n\n  // If populated path has numerics, the end `refPath` should too. For example,\n  // if populating `a.0.b` instead of `a.b` and `b` has `refPath = a.c`, we\n  // should return `a.0.c` for the refPath.\n\n  if (hasNumericPropRE.test(populatedPath)) {\n    const chunks = populatedPath.split(hasNumericPropRE);\n\n    if (chunks[chunks.length - 1] === '') {\n      throw new Error('Can\\'t populate individual element in an array');\n    }\n\n    let _refPath = '';\n    let _remaining = refPath;\n    // 2nd, 4th, etc. will be numeric props. For example: `[ 'a', '.0.', 'b' ]`\n    for (let i = 0; i < chunks.length; i += 2) {\n      const chunk = chunks[i];\n      if (\n        _remaining.length >= chunk.length + 1 &&\n        _remaining.charAt(chunk.length) === '.' &&\n        _remaining.slice(0, chunk.length) === chunk\n      ) {\n        _refPath += _remaining.substring(0, chunk.length) + chunks[i + 1];\n        _remaining = _remaining.substring(chunk.length + 1);\n      } else if (i === chunks.length - 1) {\n        _refPath += _remaining;\n        _remaining = '';\n        break;","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/helpers/populate/modelNamesFromRefPath.js#L16-L52","documentation":"Error \"Can't populate individual element in an array\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/helpers/populate/modelNamesFromRefPath.js:34 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"}