fix(model): ensure $isDeleted is set after calling doc.deleteOne() successfully#15898
Merged
fix(model): ensure $isDeleted is set after calling doc.deleteOne() successfully#15898
doc.deleteOne() successfully#15898Conversation
2 tasks
Contributor
There was a problem hiding this comment.
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 inModel.prototype.deleteOne()to set$isDeleted(true)whendeletedCount > 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.
hasezoey
reviewed
Dec 16, 2025
Collaborator
hasezoey
left a comment
There was a problem hiding this comment.
LGTM, aside from what copilot brought up about the issue id in test name
AbdelrahmanHafez
approved these changes
Dec 16, 2025
AbdelrahmanHafez
approved these changes
Dec 18, 2025
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Hafez <[email protected]>
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.
Fix #15858
Summary
Using
query.transform()instead ofquery.post()because Mongoose doesn't pass the result toquery.post(), and adding the result toquery.post()would be backwards breaking for cb-based post hooks.Examples