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
- 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Setting up a hosted MongoDB server4m 22s
-
(Locked)
Connecting to MongoDB3m 27s
-
(Locked)
Adding MongoDB and Mongoose to an Express project4m 54s
-
(Locked)
Creating a user schema for Mongoose6m 21s
-
(Locked)
Using bcrypt to hash and validate passwords1m 31s
-
(Locked)
Adding password encryption and validation to a Mongoose model5m 12s
-
(Locked)
Creating a user registration route5m 36s
-
(Locked)
Testing the form and reviewing the data in MongoDB1m 33s
-
(Locked)
-
-
-
-