O'Reilly logo
  • Patrick S thinks this is interesting:

projectSchema.statics.findByUserID = function (userid, callback) {
  this.find(
    { createdBy: userid },
    '_id projectName',
    {sort: 'modifiedOn'}
    callback);
}

This creates a new model method for us, so that we will now be able to call Model.findByUserID(userid,callback) in the same way that we called Model.findOne when creating the login functionality earlier.

Inside our method we are calling the Model.find method, passing it four parameters:

  • Query object
  • Items...

From

Cover of Mongoose for Application Development

Note

creating a custom static method