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 user schema

Creating user schema

Now, let's update the user's model and define it as a schema for the user's collection. I'll open the user entity from the entities folder and I'll remove the entire user entity. Let me define the user class and mark it as a schema using the schema decorator. With the schema decorator, I'll pass the timestamps property and set it to true. By giving this property, we will not have to explicitly state the date properties that is created at and updated at. The timestamps property will automate these properties inside the collection. Let's define the properties. I'll give the username for type string and mark it as a property. Similarly, password of type string and marking it as property. As far as the name is concerned, Mongoose is going to pluralize the schema name. So eventually the collection name will be set as users inside the database. Let's export this schema. I'll give export const user schema is equal to schema factory dot create for class and will pass the user. So let's…

Contents