From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating a user schema for Mongoose

Creating a user schema for Mongoose

From the course: Advanced Express

Start my 1-month free trial

Creating a user schema for Mongoose

- Mongoose uses schemas to define the structure and data types within a document. To create and manipulate data within a defined schema, Mongoose gives you a the concept of models. A model is the programming interface that lets you create and manipulate data based on the schema. We will now create a schema that stores users. For that I will first create a new folder. "Models inside server" and inside that folder, I will create a new file "UserModel.js". On top of this file I will bring in mongoose because mongoose require mongoose and we also want to add some functionality to validate the data and validate the email address is a solved problem so we will install a module for that. So in the terminal I run npm install --save enter module is called email-validator and while this is running let's bring it in email validator=require Email-validator Now let's start creating the actual user schema For that add const UserSchema = mongoose.Schema (); first argument which is an object that…

Contents