title: Mongoose Pre /^findOneAd/ Hook Middleware Doesn't Fire
body: <p>I have CommenentSchema:</p>
  <pre><code>const CommentSchema: Schema = new Schema(
    {
      article: {
        type: Schema.Types.ObjectId,
        ref: &quot;Article&quot;,
      },
      comment: {
        type: String,
        required: [true, &quot;Cannot post an empty comment&quot;],
      },
      commentBy: {
        type: Schema.Types.ObjectId,
        ref: &quot;User&quot;,
      },
    },
    {
      toJSON: {
        virtuals: true,
        transform: (_doc, ret) =&gt; {
          delete ret.id;
          delete ret.__v;
        },
      },
      toObject: { virtuals: true },
      timestamps: true,
    }
  </code></pre>
  <p>I'm trying to get the totalComments of an article (in a separate ArticleSchema) which I was able to achieve with aggregate and pre save middleware like so:</p>
  <pre><code>// Comment Count
  // 1 - Calc. number of comments of an article when a comment is submitted
  CommentSchema.statics.calcTotalComments = async function (articleId) {
    const stats = await this.aggregate([
      {
        $match: { article: articleId },
      },
      {
        $group: {
          _id: &quot;article&quot;,
          nComment: { $sum: 1 },
        },
      },
    ]);
    if (stats.length &gt; 0) {
      // update article
      await Article.findByIdAndUpdate(articleId, {
        totalComments: stats[0].nComment,
      });
    } else {
      // set to default
      await Article.findByIdAndUpdate(articleId, {
        totalComments: 0,
      });
    }
  };
  CommentSchema.post(&quot;save&quot;, function () {
    // points to current comment
    this.constructor.calcTotalComments(this.article);
  });
  
  </code></pre>
  <p>I also want the number of totalComments to change when a comment is deleted but it doesn't fire at pre /^findOneAnd/</p>
  <pre><code>// 2 - Calc. number of comments of an article when a comment is updated/deleted
  CommentSchema.pre&lt;Query&lt;ICommentDocument, ICommentDocument&gt;&gt;(
    /^findOneAndUpdate/,
    async function (next: Function) {
      // points to query of coment
      // @ts-ignore: igore property doc does not exist on type Query...
      this.doc = await this.model.findOne(this.getFilter());
      // @ts-ignore: igore property doc does not exist on type Query...
      console.log(this.doc);
      next();
    }
  );
  
  
  CommentSchema.post&lt;Query&lt;ICommentDocument, ICommentDocument&gt;&gt;(
    /^findOneAnd/,
    async function () {
      // @ts-ignore: igore property doc does not exist on type Query...
      await this.doc.constructor.calcTotalComments(this.doc.article);
    }
  );
  
  </code></pre>
  <p>I have tried all previous solution but none did work. Even the pre hook doesn't fire a simple console.log('hello');</p>
  <p>What am I doing wrong?</p>