Skip to content
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(document): ensure post('deleteOne') hooks are called when calling save() after subdoc.deleteOne() #14732

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #9885

Summary

It looks like when we removed remove(), we didn't make it so that post('deleteOne') hooks fire when you save() a deleted doc. This PR makes Mongoose consistently trigger post('deleteOne') middleware on subdocs when you call subdoc.deleteOne(); await topLevelDoc.save();, which is what used to happen when you did subdoc.remove(); await topLevelDoc.save();

Examples

@vkarpov15
Copy link
Collaborator Author

I also refactored the subdoc post save hook to use async/await. Looks to be about 7% faster on the mapOfSubdocs benchmark on my local, so this refactor may actually be slightly faster.

We will do some work to add promise support for kareem, to avoid the need to explicitly instantiate new Promise()

@vkarpov15 vkarpov15 added this to the 8.5 milestone Jul 8, 2024
@vkarpov15 vkarpov15 merged commit 761e551 into master Jul 8, 2024
46 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-9885 branch July 8, 2024 20:19
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.

Pre-remove hooks not called for subdocuments
1 participant