Repository navigation
fix(array): compare dates by value in indexOf() so pull() removes them (backport #16535 to 8.x) - #16590
Merged
vkarpov15 merged 1 commit intoOct 16, 2026
Conversation
MongooseArray#pull() finds matches with MongooseArray#indexOf(), which compares with `==`. Two Date objects are only `==` when they are the same instance, so pulling a date left it in the local array while the $pullAll still removed it on save. If the array was also pushed to before saving, the atomics fall back to $set and the pulled date was written back. addToSet() already compares dates by timestamp; do the same in indexOf(), which also makes includes() work for dates. (cherry picked from commit 3b76fce)
vkarpov15
approved these changes
Oct 16, 2026
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.
Summary
Backport of #16535 to 8.x.
MongooseArray#pull()finds matches withMongooseArray#indexOf(), which compares with==. TwoDateobjects are only==when they are the same instance, so on 8.x pulling a date by value leaves it in the local array even though the$pullAllremoves it on save. If the array is also pushed to before saving, the atomics fall back to$setand the pulled date is written back.The fix on master makes
indexOf()compare dates by timestamp, the same wayaddToSet()already does. It cherry-picks cleanly onto 8.x (git cherry-pick -x 3b76fce84), no changes needed.Examples
The tests added in #16535 are included. On current 8.x (8.24.5) the
matches dates by valuetest fails; with this change it passes.Ran locally on Linux, Node 24:
test/types.array.test.js(67 passing), the fullnpm testsuite (4045 passing, 0 failing, 50 pending; plain 8.x gives 4043 passing), and ESLint on the changed files.