Open harshmalviya opened 3 years ago
You can use (for mongose v6.0.11):
this.r = await this.findOne().clone();
Read details here: https://mongoosejs.com/docs/migrating_to_6.html
in mongoose v6 you don't need that pre hook any more in post hook use doc.
reviewSchema.post(/^findOneAnd/, async function (document) {
await document.constructor.calcAverageRatings(document.tour);
});
When using pre and post middlewares in review model to add ratings after editing a review, I am getting this error from the post findOneAnd middleware. This is happening because the query is already executed and we can't add anything in the document.