-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(bulkWrite): pass overwriteImmutable option to castUpdate fixes #15781 #15782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(bulkWrite): pass overwriteImmutable option to castUpdate fixes #15781 #15782
Conversation
|
@vkarpov15 please review and suggest changes if requires |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where the overwriteImmutable option was not being respected in bulkWrite operations with updateOne or updateMany. The fix ensures that users can update immutable timestamp fields like createdAt when explicitly setting both overwriteImmutable: true and timestamps: false.
Key changes:
- Pass
overwriteImmutableoption from operation tocastUpdatein bothcastUpdateOneandcastUpdateMany - Pass
timestampsoption toapplyTimestampsToUpdateto prevent deletion ofcreatedAtwhentimestamps: falseis set - Add comprehensive test coverage for the fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/helpers/model/castBulkWrite.js | Added overwriteImmutable to options passed to castUpdate and timestamps to options passed to applyTimestampsToUpdate in both castUpdateOne and castUpdateMany functions |
| test/model.updateOne.test.js | Added test case verifying that immutable createdAt can be overwritten using bulkWrite with overwriteImmutable: true and timestamps: false |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vkarpov15
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍 will backport to 7.x and 8.x.
|
Ty! |
fix: allow timestamps and overwriteImmutable in TS and JS for 7.x
fix(bulkWrite): pass overwriteImmutable option to castUpdate fixes
Fixes #15781
Summary
When using
bulkWritewithupdateOneorupdateManyoperations, theoverwriteImmutableoption was not being passed through tocastUpdate. This prevented users from updating immutable timestamp fields likecreatedAteven when explicitly settingoverwriteImmutable: trueandtimestamps: false.The issue was that in
castBulkWrite.js, theoverwriteImmutableoption from the operation was not included in the options object passed tocastUpdate, causinghandleImmutableto remove the immutable field from the update.This PR fixes the issue by:
overwriteImmutableoption from the operation tocastUpdatein bothcastUpdateOneandcastUpdateManytimestampsoption toapplyTimestampsToUpdateto prevent deletion ofcreatedAtwhentimestamps: falseis setExamples