{"record":{"id":"278bb95f7d47aa29","repo":"Automattic/mongoose","slug":"refpath-refpath-must-not-be-excluded-in-proje","errorCode":null,"errorMessage":"refPath `${refPath}` must not be excluded in projection, got ${util.inspect(queryProjection)}","messagePattern":"refPath `(.+?)` must not be excluded in projection, got (.+?)","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/helpers/populate/modelNamesFromRefPath.js","lineNumber":22,"sourceCode":"const isPathExcluded = require('../projection/isPathExcluded');\nconst lookupLocalFields = require('./lookupLocalFields');\nconst mpath = require('mpath');\nconst util = require('util');\nconst utils = require('../../utils');\n\nconst hasNumericPropRE = /(\\.\\d+$|\\.\\d+\\.)/g;\n\nmodule.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, modelSchema, queryProjection) {\n  if (refPath == null) {\n    return [];\n  }\n\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) {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/helpers/populate/modelNamesFromRefPath.js#L4-L40","documentation":"Error \"refPath `${refPath}` must not be excluded in projection, got ${util.inspect(queryProjection)}\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/helpers/populate/modelNamesFromRefPath.js:22 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"}