Skip to content

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
@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

2 participants