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.

Registering the schema

Registering the schema

Now, let's see how to register a schema in the module. We have the product schema ready. Now to register this schema, let's create a separate product controller and module file. I'll give the command nest generate controller products slash product hyphen hyphen no hyphen spec. The product controller is created. Now the module file nest generate module products slash product and of course no spec. And the product module is also created. Now let me open the product module. Here in the imports array, we have to register the product schema. For that, I'll give mongoose module dot for feature method. And inside the feature method, we have to pass the schema definition as an object. It takes two properties. First is the name property to which we assign the schema name that is basically the class name. So product dot name will be the value. It has to be defined with the dot name property everywhere. It's the basic syntax. And along with the name property, we have to define the schema…

Contents