Skip to content

Commit

Permalink
fix(populate): better handling for virtual populate under arrays
Browse files Browse the repository at this point in the history
Fix #4923
  • Loading branch information
vkarpov15 committed Jan 23, 2017
1 parent c7049b8 commit c27c294
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2740,10 +2740,15 @@ function populate(model, docs, options, callback) {
if (err) return callback(err);

var options = mod.options;
var isVirtual = mod.isVirtual;
var justOne = mod.justOne;
var _val;
var lean = options.options && options.options.lean,
len = vals.length,
rawOrder = {}, rawDocs = {}, key, val;
var lean = options.options && options.options.lean;
var len = vals.length;
var rawOrder = {};
var rawDocs = {};
var key;
var val;

// optimization:
// record the document positions as returned by
Expand All @@ -2768,8 +2773,13 @@ function populate(model, docs, options, callback) {
rawOrder[key] = [rawOrder[key], i];
}
} else {
rawDocs[key] = val;
rawOrder[key] = i;
if (isVirtual && !justOne) {
rawDocs[key] = [val];
rawOrder[key] = [i];
} else {
rawDocs[key] = val;
rawOrder[key] = i;
}
}
}
} else {
Expand Down

0 comments on commit c27c294

Please sign in to comment.