Totty.js
Totty.js

Reputation: 15831

How to extend the Schema in Mongoose?

I would like to add a static method to the Schema class, how do I do without changing the main Schema class?

thanks

Upvotes: 1

Views: 350

Answers (1)

Sangram Singh
Sangram Singh

Reputation: 7191

This is how the website documents it:

// assign a function to the "statics" object of our animalSchema
 animalSchema.statics.findByName = function (name, cb) {
 this.find({ name: new RegExp(name, 'i') }, cb);
}

Upvotes: 1

Related Questions