From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Creating product schema

Creating product schema

Now, let's update the products model and define it as a schema for the products collection. I'll open the product entity file from the entities folder, and I'll remove the entire product entity. I'll create a class named product and apply the schema decorator, giving the timestamps property to true, so that it creates the date fields inside the collection. Let's define the properties. I'll give the product name of type string and mark it as a property. Setting the required constraint to true. Similarly, the price property of type number. Setting the required to true. And the image property of type string. Here as well, I'll set the required to true. Then we will export the product schema. I will create a constant product schema is equal to schema factory dot create for class and will pass the product. Let's register the schema inside the product module. I'll remove the type ORM module and will give the mongoose module dot for feature giving the object which will take the name…

Contents