Author Profile Altaf Shaikh
Altaf Shaikh

BE Engg | Python Dev | Content Writer | Founder of TeachMeBro | Blockchain Dev | Django

Mongoose In Action - Referencing

January 25th 2021   105

Mongoose In Action - Referencing Mongoose
Mongoose In Action - Referencing Mongoose

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

A Mongoose 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 three parts:

Referencing Mongoose

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.