fix(setDefaultsOnInsert): check child filter paths before applying defaults#16031
Open
AbdelrahmanHafez wants to merge 6 commits intomasterfrom
Open
fix(setDefaultsOnInsert): check child filter paths before applying defaults#16031AbdelrahmanHafez wants to merge 6 commits intomasterfrom
AbdelrahmanHafez wants to merge 6 commits intomasterfrom
Conversation
…without dot-notation re #16030
Contributor
There was a problem hiding this comment.
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()insetDefaultsOnInsertto 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. |
…g through updatedKeys again
…prevent prototype pollution
hasezoey
reviewed
Feb 18, 2026
Collaborator
hasezoey
left a comment
There was a problem hiding this comment.
LGTM, aside from a minor nitpick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16030 re #15691 #15672
When optimizing
setDefaultsOnInsertto 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 intoupdatedKeyswhen building the filter map (e.g.extraProps.locationalso marksextraProps), so the existing lookup mechanism correctly prevents theextraPropsdefault from overwriting the filter value via$setOnInsert.