{"record":{"id":"b0cc81a2bcf4c0dd","repo":"Automattic/mongoose","slug":"refpath-must-be-a-string-or-a-function-that-retu-b0cc81","errorCode":null,"errorMessage":"`refPath` must be a string or a function that returns a string, got ${util.inspect(refPath)}","messagePattern":"`refPath` must be a string or a function that returns a string, got (.+?)","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/helpers/populate/modelNamesFromRefPath.js","lineNumber":18,"sourceCode":"'use strict';\n\nconst MongooseError = require('../../error/mongooseError');\nconst 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","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/helpers/populate/modelNamesFromRefPath.js#L1-L36","documentation":"Error \"`refPath` must be a string or a function that returns a string, got ${util.inspect(refPath)}\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/helpers/populate/modelNamesFromRefPath.js:18 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"}