Skip to content

Commit 528f125

Browse files
committed
fix(populate): handle undefined refPath values in middle of array
Fix #5377
1 parent a66f618 commit 528f125

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/model.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,11 +3360,6 @@ function getModelsMapForPopulate(model, docs, options) {
33603360
if (refPath) {
33613361
modelNames = utils.getValue(refPath, doc);
33623362
isRefPathArray = Array.isArray(modelNames);
3363-
if (isRefPathArray) {
3364-
modelNames = modelNames.filter(function(v) {
3365-
return v != null;
3366-
});
3367-
}
33683363
} else {
33693364
if (!modelNameFromQuery) {
33703365
var modelForCurrentDoc = model;
@@ -3442,6 +3437,9 @@ function getModelsMapForPopulate(model, docs, options) {
34423437
var k = modelNames.length;
34433438
while (k--) {
34443439
modelName = modelNames[k];
3440+
if (modelName == null) {
3441+
continue;
3442+
}
34453443
var _doc = Array.isArray(doc) && isRefPathArray ? doc[k] : doc;
34463444
var _ret = Array.isArray(ret) && isRefPathArray ? ret[k] : ret;
34473445
try {

0 commit comments

Comments
 (0)