What is the difference between a Mongoose schema and a model?
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.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Mongoose Schema vs Model: What's the Difference
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.
Model.create, Model.find, Model.findOne, Model.findById, Model.findByIdAndUpdate, Model.findByIdAndDelete, Model.countDocuments, Model.updateMany. Each returns a promise (with await) or a query (chainable).
Still have questions?
Browse all our FAQs or reach out to our support team
