1 00:00:02,170 --> 00:00:09,430 So now that we can store products and fetch all products, let's work on getting a single product. And 2 00:00:09,520 --> 00:00:12,300 for that, we can use our get route here, 3 00:00:12,550 --> 00:00:18,280 this parse is basically an ID which is encoded in the url, if we view the details here, you can see 4 00:00:18,280 --> 00:00:19,820 that url here, 5 00:00:19,840 --> 00:00:26,230 that is the ID as it is stored in mongodb and therefore, we can use that ID to fetch our product of 6 00:00:26,230 --> 00:00:27,450 course. 7 00:00:27,550 --> 00:00:36,340 Hence what I want to do here is I'll reuse my code here with find to find that product and replace 8 00:00:36,340 --> 00:00:38,440 that dummy code here with that code, 9 00:00:38,440 --> 00:00:44,220 however I'll not use find but find one because of course, I know that I will only find one product here 10 00:00:44,350 --> 00:00:48,660 for a given ID but that is a filter which I need to add here. 11 00:00:49,030 --> 00:00:55,240 Now I want to search for ID being equal to that ID and for that, I need to get access to the objectid 12 00:00:55,930 --> 00:01:01,810 object so I'll name that constant objectid and import it from mongodb, object ID. 13 00:01:02,050 --> 00:01:09,660 So just as I created a decimal 128 object, I can also create my own object IDs which mongodb understands. 14 00:01:09,660 --> 00:01:13,440 So now this is stored in this constant and down there, 15 00:01:13,880 --> 00:01:16,070 I can simply use that with the new keyword, 16 00:01:16,100 --> 00:01:20,800 so the objectid is a so-called constructor, a function in Javascript 17 00:01:21,020 --> 00:01:22,820 and there I can pass in a string. 18 00:01:22,820 --> 00:01:28,340 Now that string is basically extractable from the url with the help of express which is the node 19 00:01:28,400 --> 00:01:32,420 framework I'm using here with request params IDs. 20 00:01:32,420 --> 00:01:34,680 So this gives me access to the request parameters, 21 00:01:34,730 --> 00:01:41,780 so the data encoded in the url and then, I'm extracting ID because I named it ID here and that is then 22 00:01:41,780 --> 00:01:46,670 passed to this constructor which gives me an objectid object which mongodb understands. 23 00:01:46,670 --> 00:01:49,280 Find one then returns a promise, 24 00:01:49,280 --> 00:01:56,810 so I have catch and then. In the error case, I'll reuse my error code from down there and simply send an 25 00:01:56,840 --> 00:02:06,860 error response, in the success case I should get my project, my product document and then I can return 26 00:02:06,980 --> 00:02:10,270 this with status code 200 for 27 00:02:10,280 --> 00:02:13,780 I got something and simply pass it as 28 00:02:13,830 --> 00:02:15,990 json data to my frontend, 29 00:02:16,130 --> 00:02:20,490 so now this should be some code that works and allows me to fetch a single product. 30 00:02:20,630 --> 00:02:28,730 If you save all files, you can restart your backend server and now try reloading that page, 31 00:02:30,440 --> 00:02:35,470 now it almost works but I get an issue regarding the number decimal. 32 00:02:35,610 --> 00:02:42,350 Well the problem here is that a single product has its price stored as a decimal, decimal 128 bit and 33 00:02:42,350 --> 00:02:43,940 therefore, I need to convert it, 34 00:02:44,030 --> 00:02:52,580 so I will simply set product doc price equal to product doc price toString, what we already did earlier 35 00:02:52,970 --> 00:02:55,530 just to make sure that this is handled correctly. 36 00:02:55,580 --> 00:03:00,330 After this little addition, we can restart the backend server once again 37 00:03:00,500 --> 00:03:05,820 and now if we reload that front page, we see the product data on the detail page. 38 00:03:05,820 --> 00:03:11,160 So now fetching all products is working, fetching a single product is working, now 39 00:03:11,210 --> 00:03:13,020 of course adding products is working, 40 00:03:13,040 --> 00:03:16,260 now I want to make sure that editing and deleting works too. 41 00:03:16,340 --> 00:03:18,060 So that is what I'll work on next.