From 9402efdd677e1e920fcf9c5241bcefbcb98da800 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 23 Dec 2021 12:27:20 -0500 Subject: [PATCH] fix(populate): handles refPath underneath map of subdocuments Fix #9359 --- lib/helpers/populate/modelNamesFromRefPath.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/helpers/populate/modelNamesFromRefPath.js b/lib/helpers/populate/modelNamesFromRefPath.js index c441f565e01..89269987492 100644 --- a/lib/helpers/populate/modelNamesFromRefPath.js +++ b/lib/helpers/populate/modelNamesFromRefPath.js @@ -2,6 +2,8 @@ const MongooseError = require('../../error/mongooseError'); const isPathExcluded = require('../projection/isPathExcluded'); +const lookupLocalFields = require('./lookupLocalFields'); +const mpath = require('mpath'); const util = require('util'); const utils = require('../../utils'); @@ -44,13 +46,13 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod } } - const refValue = utils.getValue(_refPath, doc); + const refValue = mpath.get(_refPath, doc, lookupLocalFields); let modelNames = Array.isArray(refValue) ? refValue : [refValue]; modelNames = utils.array.flatten(modelNames); return modelNames; } - const refValue = utils.getValue(refPath, doc); + const refValue = mpath.get(refPath, doc, lookupLocalFields); let modelNames; if (modelSchema != null && modelSchema.virtuals.hasOwnProperty(refPath)) {