If you have not done the previous steps, or have no setup your mlab database.

Great lets setup our model which will be the structure for the database, which by default setup a separate collection for that model. Let first go to our models folder in our server folder outside of our src directory. Then create a product.js file for our product model, and a user.js file for our users.

Now go to our product.js files, and start defining our model. To start import mongoose module. Then set a variable called Schema that will equal an instance of the Schema class used for defining structure of the data that is inserted into the data.

Define the properties of the object, with a name, description, and price.

To create a model, use the Schema model method, with the name of model as the first argument, and the object as the second argument. Then export it.

Now lets define our User model which we will used later for authentication with Auth0. Go to your user.js file, and define your model.

Now let define your model, which will have a username, name, email, and auth0_id. We will go through auth0 later in the tutorial.

Now lets exports our modal with the name as the first argument, and a object passed in as the model.

When we insert these models to the database, it will auto-generate an id by default. NOTE: Do not run your server file yet, we still have to define our controller file next tutorial.

Well we have our models set up.

Now we will starting implementing these models in Step 3C.

Here the git repo for reference.

Here is the next step:

Happy Coding!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store