Skip to content

Commit 360b417

Browse files
committed
refactor: quick cleanup to avoid building curPath when not necessary with #14099
1 parent 07dba1b commit 360b417

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/helpers/populate/assignVals.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ module.exports = function assignVals(o) {
144144

145145
const parts = _path.split('.');
146146
let cur = docs[i];
147-
let curPath = parts[0];
148147
for (let j = 0; j < parts.length - 1; ++j) {
149148
// If we get to an array with a dotted path, like `arr.foo`, don't set
150149
// `foo` on the array.
@@ -160,14 +159,14 @@ module.exports = function assignVals(o) {
160159
// If nothing to set, avoid creating an unnecessary array. Otherwise
161160
// we'll end up with a single doc in the array with only defaults.
162161
// See gh-8342, gh-8455
162+
const curPath = parts.slice(0, j + 1).join('.');
163163
const schematype = originalSchema._getSchema(curPath);
164164
if (valueToSet == null && schematype != null && schematype.$isMongooseArray) {
165165
break;
166166
}
167167
cur[parts[j]] = {};
168168
}
169169
cur = cur[parts[j]];
170-
curPath += parts[j + 1] ? `.${parts[j + 1]}` : '';
171170
// If the property in MongoDB is a primitive, we won't be able to populate
172171
// the nested path, so skip it. See gh-7545
173172
if (typeof cur !== 'object') {

0 commit comments

Comments
 (0)