How do I define methods in a Mongoose model?

You didn’t specify whether you were looking to define class or instance methods. Since others have covered instance methods, here’s how you’d define a class/static method:

animalSchema.statics.findByName = function (name, cb) {
    return this.find({ 
        name: new RegExp(name, 'i') 
    }, cb);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)