Setup Schemas and Models for Users and Course Collection
Learn to set up schemas and models to use in a Node.js application.
Mongoose models and schemas
The Mongoose package is an object data modeling library designed to work in an asynchronous environment. It’s also similar to an
-
Easy data validation on the fly.
-
It’s asynchronous by default. That is, we can set predefined events before a document gets saved.
-
It provides an easy abstraction of data.
The Mongoose model allows us to access data from MongoDB in an object-oriented pattern. To create a Mongoose model, we need to define a specific schema object. Once that’s done, we’ll need to register the model with Mongoose so we can access the schema anywhere in our application.
The illustration below shows the relationship that exists between the database schema that we’ll create in our application:
Get hands-on with 1400+ tech skills courses.