Yes. userSchema.methods.fullName = function() { ... } adds an instance method. userSchema.statics.findByEmail = function(email) { ... } adds a static method. Use them to keep domain logic close to the data.
Mongoose Schema vs Model: What's the Difference
Can you add custom methods to a Mongoose schema?
The answer
More FAQs in Mongoose Schema vs Model: What's the Difference
A schema defines the shape of a document (fields, types, validation, defaults). A model is a constructor compiled from a schema; it is what you use to query and save documents. Schema is the blueprint; model is the database interface.
Define a schema with new mongoose.Schema({ ... }), then compile a model with mongoose.model('User', userSchema). The model is what you use to create, read, update, and delete documents.
Field types (String, Number, Date, ObjectId), validation (required, min, max, enum, match), defaults, indexes (unique, sparse), virtuals, middleware hooks, and instance/static methods.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.