fix(documentarray): reindex subdocs after reordering#16282
Draft
AbdelrahmanHafez wants to merge 12 commits into
Draft
fix(documentarray): reindex subdocs after reordering#16282AbdelrahmanHafez wants to merge 12 commits into
AbdelrahmanHafez wants to merge 12 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes document array subdocument index bookkeeping after removals so later nested mutations mark the correct path.
Changes:
- Reindexes surviving subdocuments after
pull(),shift(), andsplice(). - Preserves populated cache updates in the same wrappers.
- Adds regression coverage for saving after removal and mutating the first remaining subdocument.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/types/documentArray/methods/index.js |
Adds subdocument index restamping after selected document-array removal operations. |
test/types.documentarray.test.js |
Adds regression tests for pull(), splice(), and shift() reindex behavior. |
14e4e57 to
f1f0559
Compare
| */ | ||
|
|
||
| reverse() { | ||
| const ret = _baseReverse.call(this); |
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.
Document array operations that remove or reorder entries can leave surviving subdocs with stale
__indexvalues. After operations likepull(),shift(),splice(),$shift(),unshift(), positionedpush(),sort(), orreverse(), a subdoc can still think it lives at its previous array index. A later nested change can then mark and save the wrong path, for exampleaddresses.1.cityinstead ofaddresses.0.city.This PR:
push()on the fast path, because the new subdoc is already cast with the correct appended indexdoc.populated('array.refPath')order, includingsort()andreverse()reverse()register a full-array$set, matching other reorder operations and avoiding stale pending atomics after a prior$push