From the course: Databases for Node.js Developers

Unlock the full course today

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

Define your first schema and model

Define your first schema and model

From the course: Databases for Node.js Developers

Start my 1-month free trial

Define your first schema and model

- [Instructor] As we learned before Mongoose relies on schemas and models. And in this video, we will create a schema and a model for storing items. So as we see on this form, our item is represented by an SKU which is an item number, and name and the price. So let's head over to Visual Studio code and implement that. For that to go into models, so this directory exists already. In there, I click on item.js. As you see, this file is still empty and we will now start implementing the schema. So I start with adding Mongoose, const mongoose = require('mongoose') and then I start defining the schema. Const ItemSchema = mongoose.Schema. And in there we add now a configuration object with our schema definition. First we define the SKU. And the SKU as the type, and the type should be a number. So it should be numeric. It should be required, so at required true And I want it to be indexed. So there should be a database index…

Contents