Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Fix #15800

Summary

Make bulkSave() increment the document's version on successful save.

Need to backport this to 7.x.

Examples

@vkarpov15 vkarpov15 added this to the 8.20.2 milestone Nov 28, 2025
Copilot finished reviewing on behalf of vkarpov15 November 28, 2025 18:01
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

This PR fixes issue #15800 by ensuring that bulkSave() increments the document's version key (__v) after a successful save, bringing it in line with the behavior of the regular save() method.

Key changes:

  • Refactored version increment logic into a reusable _applyVersionIncrement() helper method in Document
  • Modified bulkSave() to call this helper after successful writes
  • Added comprehensive test coverage for version increment behavior in bulkSave()

Reviewed changes

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

File Description
lib/document.js Adds new _applyVersionIncrement() helper method to centralize version increment logic
lib/model.js Refactors $__save() to use the new helper and updates handleSuccessfulWrite() (used by bulkSave()) to increment versions on successful saves
test/model.test.js Adds comprehensive test covering version increment on successful save, no increment on validation errors, and correct behavior with different field types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Looks OK to me, but i agree with both of copilots comments / suggestions (function naming & comment location).

Just for clarification, the added test is not meant to increment version above 1?

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vkarpov15
Copy link
Collaborator Author

"Just for clarification, the added test is not meant to increment version above 1?" <-- No, because Mongoose only increments version on array updates. Updating a string property doesn't trigger a version update by default.

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.

4 participants