Skip to content

why not use this simple line in one single method instead of that confusing way to access doc and model! #190

@Mahmoud-AbouDeghedy

Description

@Mahmoud-AbouDeghedy
reviewSchema.post(/^findOneAnd/, async function (doc) {
  await this.model.calcAverageRatings(doc.tour);

instead of

reviewSchema.pre(/^findOneAnd/, async function(next) {
this.r = await this.findOne();
// console.log(this.r);
next();
});

reviewSchema.post(/^findOneAnd/, async function() {
// await this.findOne(); does NOT work here, query has already executed
await this.r.constructor.calcAverageRatings(this.r.tour);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions