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.
Deleting a document from MongoDB - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Deleting a document from MongoDB
Now, let's see how to delete a document from the collection. Inside the service file, I'll create a delete method and pass the ID parameter of type string. And I will return await this.productModel.findById and delete will pass the ID.execute. So this is going to delete the document from the collection based on the document ID. Now inside the controller, I'll give the delete route handler and pass the dynamic ID. Creating a delete method, passing the param decorator to get the ID value, and we'll store it inside the ID property of type string. Then again, we will need the ID validation logic. So I'll quickly bring the same validation logic here in the delete method as well. Next I'll create a product constant and assign the delete method from product service and pass the ID. And we will return the product. Let's save this and check the output. I'll select the delete request type and set the route path. Let's delete the first product that is Apple. So I'll copy the ID and paste it…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Understanding controllers5m 10s
-
(Locked)
Controller fundamentals (@Get handler)4m 21s
-
(Locked)
Controller fundamentals (Headers)3m 35s
-
(Locked)
Controller fundamentals (@Post handler)8m 57s
-
(Locked)
Controller fundamentals (@Post handler), part 2 with modules6m 56s
-
(Locked)
Controller fundamentals (fetching params)6m 44s
-
(Locked)
Controller fundamentals (@Put handler)10m 18s
-
(Locked)
Controller fundamentals (@Patch handler)4m 8s
-
(Locked)
Controller fundamentals (@Delete handler)3m 24s
-
(Locked)
Request object4m 42s
-
(Locked)
Response object2m 6s
-
(Locked)
Fetching queries3m 24s
-
(Locked)
@HttpCode vs. @Res decorator3m 22s
-
(Locked)
HTTP response status2m 53s
-
(Locked)
-
-
(Locked)
Introduction to pipes1m 59s
-
(Locked)
Built-in pipes (ParseIntPipe)2m 40s
-
(Locked)
Built-in pipes (ParseFloatPipe)1m 7s
-
(Locked)
Built-in pipes (ParseBooleanPipe)2m 25s
-
(Locked)
Built-in pipes (ParseArrayPipe)2m 59s
-
(Locked)
Built-in pipes (ParseUUIDPipe)4m 12s
-
(Locked)
Built-in pipes (ValidationPipe)5m 52s
-
(Locked)
Validating empty fields3m 34s
-
(Locked)
Validating field length3m 4s
-
(Locked)
Custom validation messages3m 2s
-
(Locked)
Validating field using @IsEnum() validator4m 7s
-
(Locked)
Validating dates in Nest.js2m 31s
-
(Locked)
Validating optional fields2m 33s
-
(Locked)
Validating regex pattern3m 11s
-
(Locked)
Creating a custom pipe6m 39s
-
(Locked)
Understanding ArgumentMetadata (metadata.type)3m 40s
-
(Locked)
Assignment: Custom pipe (handling different "type" arguments)3m 56s
-
(Locked)
Understanding ArgumentMetadata (metadata.metatype)5m
-
(Locked)
Understanding ArgumentMetadata (metadata.data)3m 37s
-
(Locked)
Implementing global pipes2m 30s
-
(Locked)
-
-
(Locked)
Introduction to Nest middlewares3m 46s
-
(Locked)
Implementing middleware3m 45s
-
(Locked)
Registering a middleware5m 20s
-
(Locked)
Route-specific middleware5m 48s
-
(Locked)
Assignment: Checking Content-Type with middleware4m
-
(Locked)
Handling route wildcards3m 19s
-
(Locked)
Middleware for specific route handlers4m 38s
-
(Locked)
Excluding routes3m 49s
-
(Locked)
Controller-driven route middleware2m 15s
-
(Locked)
Understanding functional middleware4m 26s
-
(Locked)
Applying multiple middlewares6m 51s
-
(Locked)
Applying global middlewares3m 52s
-
(Locked)
Assignment: Password encryption middleware10m 19s
-
(Locked)
-
-
(Locked)
Introduction to guards4m 14s
-
(Locked)
Understanding guard5m 33s
-
(Locked)
Understanding ExecutionContext6m 50s
-
(Locked)
Accessing arguments with getArgs()3m 42s
-
(Locked)
Limiting controller access with guard4m 6s
-
(Locked)
Understanding switchToHttp() method4m 59s
-
(Locked)
Assignment: API key authorization6m 10s
-
(Locked)
Applying multiple guards3m 14s
-
(Locked)
Defining custom metadata5m 6s
-
(Locked)
Setting custom metadata: A better way3m 25s
-
(Locked)
Applying role for specific handlers10m 3s
-
(Locked)
Applying multiple roles1m 35s
-
(Locked)
Applying global guards4m 46s
-
(Locked)
-
-
(Locked)
Introduction to interceptors3m
-
(Locked)
Understanding interceptor5m 54s
-
(Locked)
Assignment: Transforming response data4m 42s
-
(Locked)
Assignment: Modifying request headers3m 49s
-
(Locked)
Assignment: Hiding sensitive information5m 50s
-
(Locked)
Exception mapping3m 23s
-
(Locked)
Data validation with interceptor5m 37s
-
(Locked)
Authentication and authorization4m 24s
-
(Locked)
Applying global interceptors2m 39s
-
(Locked)
-
-
(Locked)
Introduction to MyStore application2m 43s
-
(Locked)
Rendering template on server4m 41s
-
(Locked)
Creating navbar with "includes"3m 31s
-
(Locked)
Creating home interface9m 6s
-
(Locked)
Conditional rendering: No product found2m 26s
-
(Locked)
Configuring add product route2m 29s
-
(Locked)
Creating "add product" interface5m 51s
-
(Locked)
Configuring edit product route1m 49s
-
(Locked)
Interface & functionality: Edit product4m 10s
-
(Locked)
-
-
(Locked)
Section introduction2m 33s
-
(Locked)
Setting up the sign-up route2m 24s
-
(Locked)
Designing the sign-up form2m 53s
-
(Locked)
Implementing show/hide password functionality4m 40s
-
(Locked)
Validating password2m 32s
-
(Locked)
Registering user to the database6m 50s
-
(Locked)
Configuring login page2m 12s
-
(Locked)
Validating user and sending cookie4m 41s
-
(Locked)
Reading a cookie2m 13s
-
(Locked)
Rendering DOM based on login status3m 48s
-
(Locked)
Implementing logout1m 20s
-
(Locked)
Configuring Express-Session2m 54s
-
(Locked)
Sending and reading session cookie3m 40s
-
(Locked)
Storing sessions in MySQL3m 44s
-
(Locked)
Destroying the session: Logout1m 42s
-
(Locked)
Optimizing session storage4m 15s
-
(Locked)
Implementing JWT token6m 51s
-
(Locked)
Validating request with middleware5m
-
(Locked)
Conditional rendering with token6m 14s
-
(Locked)
Hashing the password on sign-up3m 51s
-
(Locked)
Validating login credentials2m 15s
-
(Locked)
Finalizing MyStore application4m 20s
-
(Locked)
-
-
(Locked)
Connecting to MongoDB database3m 32s
-
(Locked)
Creating a schema3m 26s
-
(Locked)
Registering the schema2m 7s
-
(Locked)
Create and save product to MongoDB5m 24s
-
(Locked)
Fetching documents from MongoDB3m 58s
-
(Locked)
Updating a document in MongoDB3m 29s
-
(Locked)
Deleting a document from MongoDB1m 51s
-
(Locked)