Skip to content

Comments

fix(setDefaultsOnInsert): check child filter paths before applying defaults#16031

Open
AbdelrahmanHafez wants to merge 6 commits intomasterfrom
fix-gh-16030-dot-notation-upsert
Open

fix(setDefaultsOnInsert): check child filter paths before applying defaults#16031
AbdelrahmanHafez wants to merge 6 commits intomasterfrom
fix-gh-16030-dot-notation-upsert

Conversation

@AbdelrahmanHafez
Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez commented Feb 17, 2026

Fixes #16030 re #15691 #15672

When optimizing setDefaultsOnInsert to avoid computing all modified paths, in 106364f54, we missed adding checks for child paths with dot-notation in the filter. This PR precomputes parent prefixes into updatedKeys when building the filter map (e.g. extraProps.location also marks extraProps), so the existing lookup mechanism correctly prevents the extraProps default from overwriting the filter value via $setOnInsert.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in setDefaultsOnInsert where dot-notation paths in the upsert filter (for nested/sub-schema fields) were not being treated as “modified”, causing defaults to be applied via $setOnInsert in a way that prevented those nested filter fields from being included in the inserted document.

Changes:

  • Update isModified() in setDefaultsOnInsert to treat filter child paths (dot-notation) as modified.
  • Add regression tests covering dot-notation filter paths with sub-schema defaults and verifying defaults still apply when no dot-notation filter path exists.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/helpers/setDefaultsOnInsert.js Adds detection for child (dot-notation) filter paths so defaults don’t override/omit nested filter fields during upsert.
test/model.findOneAndUpdate.test.js Adds tests to verify dot-notation filter fields are included in upserted docs and defaults still apply when appropriate.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@AbdelrahmanHafez AbdelrahmanHafez marked this pull request as ready for review February 17, 2026 06:50
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, aside from a minor nitpick.

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: findOneAndUpdate upsert ignores dot-notation fields in filter since 8.19.2

2 participants