Skip to content

Commit

Permalink
refactor: quick cleanup to avoid building curPath when not necessary …
Browse files Browse the repository at this point in the history
…with #14099
  • Loading branch information
vkarpov15 committed Nov 19, 2023
1 parent 07dba1b commit 360b417
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/helpers/populate/assignVals.js
Expand Up @@ -144,7 +144,6 @@ module.exports = function assignVals(o) {

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

0 comments on commit 360b417

Please sign in to comment.