mongoose Mongoose Schemas Schema methods


Example

Methods can be set on Schemas to help doing things related to that schema(s), and keeping them well organized.

userSchema.methods.normalize = function() {
    this.name = this.name.toLowerCase();
};

Example usage:

erik = new User({
    'name': 'Erik',
    'password': 'pass'
});
erik.normalize();
erik.save();