1 00:00:01,150 --> 00:00:03,270 And now as the final one 2 00:00:03,270 --> 00:00:05,410 of the four CRUD operations, 3 00:00:05,410 --> 00:00:07,463 we have deleting documents. 4 00:00:08,550 --> 00:00:11,560 And so by now this should already be pretty familiar. 5 00:00:11,560 --> 00:00:13,910 And that's why I want to leave this one to you 6 00:00:13,910 --> 00:00:16,620 as a challenge, all right? 7 00:00:16,620 --> 00:00:18,870 So again, this one is gonna be pretty similar 8 00:00:18,870 --> 00:00:21,920 to update tour only with a small number 9 00:00:21,920 --> 00:00:24,290 of differences, but I think you can figure out 10 00:00:24,290 --> 00:00:27,480 how it works, for example, using the documentation 11 00:00:27,480 --> 00:00:30,810 and of course the other handle functions as an example. 12 00:00:30,810 --> 00:00:33,380 Okay, so keep in mind that here for example 13 00:00:33,380 --> 00:00:36,210 we used find by ID and update 14 00:00:36,210 --> 00:00:38,520 and so you probably can already guess 15 00:00:38,520 --> 00:00:42,960 how this method is gonna be called in delete tour. 16 00:00:42,960 --> 00:00:43,810 All right. 17 00:00:43,810 --> 00:00:45,030 And again, if you're not sure, 18 00:00:45,030 --> 00:00:47,380 you can take a look at the documentation 19 00:00:47,380 --> 00:00:49,950 and what kind of data it expects 20 00:00:49,950 --> 00:00:52,723 and then based on all that, try to implement it. 21 00:00:53,610 --> 00:00:54,810 Okay. 22 00:00:54,810 --> 00:00:56,910 So please pause the video here and take a minute 23 00:00:56,910 --> 00:00:59,013 to really try to do it on your own. 24 00:01:02,970 --> 00:01:05,880 Okay, hope you got that one to work 25 00:01:05,880 --> 00:01:08,443 and anyway, here goes my quick solution. 26 00:01:09,410 --> 00:01:12,510 So again, defining this one as an async function 27 00:01:14,600 --> 00:01:16,513 then try catch. 28 00:01:19,900 --> 00:01:24,623 Here is the error and then let's move this one up. 29 00:01:26,910 --> 00:01:31,910 Get this error response from over here. 30 00:01:32,380 --> 00:01:35,550 And now we are gonna use 31 00:01:35,550 --> 00:01:37,310 tour.findByIdAndDelete 32 00:01:42,513 --> 00:01:45,359 and now all this method here actually needs 33 00:01:45,359 --> 00:01:47,106 is the tour ID. 34 00:01:47,106 --> 00:01:51,910 So req.params.id and I hope you figured 35 00:01:51,910 --> 00:01:54,670 this one out from the documentation. 36 00:01:54,670 --> 00:01:57,390 Then of course we need to await in order 37 00:01:57,390 --> 00:01:59,600 for the deletion actually to happen 38 00:01:59,600 --> 00:02:01,540 and that's actually alt. 39 00:02:01,540 --> 00:02:03,780 So in this case, we actually don't save anything 40 00:02:03,780 --> 00:02:06,500 to any variable because remember, 41 00:02:06,500 --> 00:02:08,300 we actually don't send anything back 42 00:02:08,300 --> 00:02:09,900 to the client, okay. 43 00:02:09,900 --> 00:02:13,670 So in a RESTful API, it is a common practice not 44 00:02:13,670 --> 00:02:15,850 to send back any data to the client 45 00:02:15,850 --> 00:02:19,020 when there was a delete operation, okay. 46 00:02:19,020 --> 00:02:23,260 And also the 204 is kind of a standard as well. 47 00:02:23,260 --> 00:02:26,470 So give us a save now and it should actually already work 48 00:02:26,470 --> 00:02:27,610 like this. 49 00:02:27,610 --> 00:02:31,763 And so to start, let's just create some stupid tour here. 50 00:02:35,290 --> 00:02:37,620 So let's create a Jonas tour here. 51 00:02:37,620 --> 00:02:41,200 Give it a save and so, 52 00:02:41,200 --> 00:02:44,960 when we get all tours, indeed it's gonna be here 53 00:02:44,960 --> 00:02:47,233 and so let's go ahead, copy the ID, 54 00:02:48,170 --> 00:02:52,450 then open or delete tour route here 55 00:02:52,450 --> 00:02:57,270 and then all we need is to really send this delete request 56 00:02:57,270 --> 00:03:00,670 to this route, hit send. 57 00:03:01,630 --> 00:03:05,550 And so again, we get back the 204 status code 58 00:03:05,550 --> 00:03:09,900 and Postman in that case actually doesn't display anything. 59 00:03:09,900 --> 00:03:10,733 All right. 60 00:03:12,100 --> 00:03:15,400 And just to make sure, let's confirm it very quick. 61 00:03:15,400 --> 00:03:17,500 And yeah, it's gone from here. 62 00:03:17,500 --> 00:03:20,630 And so our tour was effectively deleted. 63 00:03:20,630 --> 00:03:22,830 Okay, now if you didn't manage 64 00:03:22,830 --> 00:03:25,290 to complete the challenge on your own, 65 00:03:25,290 --> 00:03:27,370 then of course that's no problem at all. 66 00:03:27,370 --> 00:03:29,800 I just wanted you to think about it 67 00:03:29,800 --> 00:03:32,140 and most of all take a look at the documentation 68 00:03:32,140 --> 00:03:34,010 on your own because it really makes 69 00:03:34,010 --> 00:03:36,290 all the difference for you to start practice 70 00:03:36,290 --> 00:03:38,900 this kind of stuff as soon as possible. 71 00:03:38,900 --> 00:03:40,930 Anyway, with this we implemented 72 00:03:40,930 --> 00:03:43,170 the basic CRUD operations. 73 00:03:43,170 --> 00:03:46,200 The next video we will then finally really start 74 00:03:46,200 --> 00:03:48,960 to model or tour a bit better. 75 00:03:48,960 --> 00:03:50,610 So right now we only have names, 76 00:03:50,610 --> 00:03:54,000 prices, and ratings, and that's not really enough 77 00:03:54,000 --> 00:03:56,750 to describe a tour and so yeah, 78 00:03:56,750 --> 00:03:59,620 in the next video we will kind of create 79 00:03:59,620 --> 00:04:02,780 a better, a bigger, more complete model. 80 00:04:02,780 --> 00:04:04,380 So I hope to see you there soon.