What is the use of mongoose methods and statics? What is the use of mongoose methods and statics? mongoose mongoose

What is the use of mongoose methods and statics?


Database logic should be encapsulated within the data model. Mongoose provides 2 ways of doing this, methods and statics. Methods adds an instance method to documents whereas Statics adds static "class" methods to the Models itself.

Given the example Animal Model below:

var AnimalSchema = mongoose.Schema({  name: String,  type: String,  hasTail: Boolean});module.exports = mongoose.model('Animal', AnimalSchema);