From the course: MERN Essential Training (2020)

Unlock the full course today

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

Set up your schema

Set up your schema

From the course: MERN Essential Training (2020)

Start my 1-month free trial

Set up your schema

- [Instructor] Before we start adding operations to a database, and the corresponding end points, we need to create our schema. The schema is what dictates the types of data and the structure of your data, your database takes. In other words, if you define the first-name key to take only string data, the database will not accept anything else. Therefore, the schema defines the rules related to what your database can accept. So let's go ahead and do this. So I'm back in the player model inside of the models folder, and the first thing I'm going to do is import Mongoose from 'Mongoose', and then I'll create a new object called schema, and I will use mongoose.Schema, like so. So basically I just created a variable that holds the schema from Mongoose. So now we can create a schema, so we'll create a new object, and we'll export it, and we'll call this one PlayerSchema, and we'll use a new schema to create it, like so, and…

Contents