I have an application in which I manage categories and subcategories.
So each time I delete a category, I have a mongoose middleware that deletes all the subcategories who belong to it.
schema.post('findOneAndDelete',
(category: CategoryDocument) => subcategoryModel.deleteMany({ category: category.id }))
That works fine when I delete just one category, what happens when I delete multiple?
I tried registering a deleteMany middleware like so:
schema.post('deleteMany',
(deletedQueryResult: any) => {})
But the deleteMany middleware just sends to my callback the result of the query (the time it took, number of deleted documents and some internal mongoose/mongodb properties).
Is there anyway I can get the deleted documents or their ids inside a mongoose middleware?
If not what are my other options here?
所有评论(0)