Skip to content

Commit f4bd463

Browse files
committed
fix(populate): make populate virtual consistently an empty array if local field is only empty arrays
Fix #8230
1 parent ca4f52b commit f4bd463

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/model.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -4120,10 +4120,11 @@ function populate(model, docs, options, callback) {
41204120
assignmentOpts.excludeId = excludeIdReg.test(select) || (select && select._id === 0);
41214121

41224122
if (ids.length === 0 || ids.every(utils.isNullOrUndefined)) {
4123-
// Ensure that we set populate virtuals with count option to 0 even
4124-
// if we don't actually execute a query.
4123+
// Ensure that we set populate virtuals to 0 or empty array even
4124+
// if we don't actually execute a query because they don't have
4125+
// a value by default. See gh-7731, gh-8230
41254126
--_remaining;
4126-
if (mod.count) {
4127+
if (mod.count || mod.isVirtual) {
41274128
_assign(model, [], mod, assignmentOpts);
41284129
}
41294130
continue;

0 commit comments

Comments
 (0)