Mongoose In Action - Referencing
January 25th 2021 229
So, In this section we will see a subtle difference between Mongoose Schema and Model, after that we will start working with mongoose and we will proceed further step by step explain each concept.
Mongoose Schema vs. Model
model is a wrapper on the Mongoose
schema. A Mongoose schema defines the structure of the document, default values, validators, etc., whereas a Mongoose model provides an interface to the database for creating, querying, updating, deleting records, etc.
Don't Jump for coding right now, have some patience and for now just read the sections, in furthur section we will create and setup the project step by step : )
Creating a Mongoose model comprises primarily of
const mongoose = require('mongoose')
This reference will be the same as the one that was returned when we connected to the database, which means the schema and model definitions will not need to explicitly connect to the database, we will see database connection in furthur section.
now , lets create a
reference to Schema class from mongoose:
const Schema = mongoose.Schema;
So thats it for this section in next section we will create our very own Schema.