Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

Fix #15858

Summary

Using query.transform() instead of query.post() because Mongoose doesn't pass the result to query.post(), and adding the result to query.post() would be backwards breaking for cb-based post hooks.

Examples

@vkarpov15 vkarpov15 added this to the 8.20.4 milestone Dec 15, 2025
Copilot AI review requested due to automatic review settings December 15, 2025 21:05
@vkarpov15 vkarpov15 requested review from AbdelrahmanHafez, Copilot and hasezoey and removed request for Copilot December 15, 2025 21:07
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 an issue where doc.$isDeleted() was not being set to true after successfully calling doc.deleteOne(). The fix uses query.transform() to check the deletedCount property in the MongoDB result and sets $isDeleted(true) only when the deletion succeeds.

Key changes:

  • Added query.transform() hook in Model.prototype.deleteOne() to set $isDeleted(true) when deletedCount > 0
  • Added comprehensive tests covering successful deletion, failed deletion, and no-op behavior when already deleted

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/model.js Adds transform hook to set $isDeleted(true) after successful deleteOne operation
test/document.test.js Adds tests verifying $isDeleted is set correctly after deleteOne, including success and failure cases

💡 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.

LGTM, aside from what copilot brought up about the issue id in test name

vkarpov15 and others added 2 commits December 18, 2025 12:38
@vkarpov15 vkarpov15 merged commit fe8d162 into 8.x Dec 18, 2025
108 of 109 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15858 branch December 19, 2025 10:41
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