title: Mongoose - use instance method in query helper
body: <p>I'm trying to use my custom method inside my query helper function that does where() operation.</p>
  <pre class="lang-js prettyprint-override"><code>FoodSchema.query.byUser = function(user): Query&lt;any, Document&lt;IFood&gt;&gt; &amp; ProjectQueryHelpers {
    return this.where({ user: new Types.ObjectId(user) }).getPublicData(); //this doesn't work
  };
  
  FoodSchema.methods.getPublicData =  function() {
    const {name,calories,mealId,date,user} = this;
    return {
      id:this._id.toString(),
      name,calories,mealId,date,
      user:user._id.toString()
    };
  };
  </code></pre>
  <p>I get this error:</p>
  <blockquote>
  <p>TypeError: this.where(...).getPublicData is not a function</p>
  </blockquote>
  <p>This probably is not the correct way to go. But I figured if populate() and other methods are used there then perhaps this should be similar ?</p>