deleteMany documents in pre middleware of delete #11035
Answered
by
vkarpov15
arashi-dev
asked this question in
Q&A
-
Hello. @pre(/remove|delete/i, async function (this: DocumentType<Comment>) {
await CommentModel.deleteMany({ parentId: this._id })
})
export class Comment {
...
}
export const CommentModel = getModelForClass(Comment) it makes an infinite loop I think because I am deleting a model document in its |
Beta Was this translation helpful? Give feedback.
Answered by
vkarpov15
Dec 5, 2021
Replies: 1 comment
-
Try @pre(/remove|delete/i, { document: true, query: false}, async function (this: DocumentType<Comment>) {
await CommentModel.deleteMany({ parentId: this._id })
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Uzlopak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try