1 00:00:02,310 --> 00:00:09,120 So we get our application and now we want to integrate mongodb into nodejs. Now to do that, you can 2 00:00:09,120 --> 00:00:13,490 dive into the official docs and there, choose mongodb drivers. 3 00:00:13,570 --> 00:00:18,990 There you'll find instructions on how to install and use the driver for the language, the programming 4 00:00:18,990 --> 00:00:21,340 language your application uses. You 5 00:00:21,370 --> 00:00:27,120 see there are a bunch of languages and for us, nodejs, this one is the relevant driver. So you can click 6 00:00:27,120 --> 00:00:27,580 on that 7 00:00:27,600 --> 00:00:31,520 and we are forwarded to the docs of that specific driver. 8 00:00:31,530 --> 00:00:38,100 Now there, you can simply choose the latest documentation and now learn more on how to use that driver 9 00:00:38,280 --> 00:00:43,020 and you see, you learn how to install the driver and then you have a quick start and some instructions 10 00:00:43,020 --> 00:00:46,550 on how to do crud operations and how to connect and so on 11 00:00:46,710 --> 00:00:52,050 and you should find this for every driver. The documentation might look different but you should find 12 00:00:52,050 --> 00:00:58,200 similar guides for every driver so that you can learn how to use that driver with your language 13 00:00:58,290 --> 00:01:02,040 and that already gives you like most of the knowledge you need. 14 00:01:02,280 --> 00:01:09,390 You also can dive into the API documentation to see a list of all methods or all objects that are part 15 00:01:09,470 --> 00:01:10,770 of this driver, 16 00:01:10,770 --> 00:01:15,770 for example here you also see the constructors for decimal 128 bit objects 17 00:01:15,780 --> 00:01:20,910 in case you want to store such a decimal, if you remember the numbers module of this course because 18 00:01:21,150 --> 00:01:26,910 nodejs is based on javascript and as you as a javascript developer should know, every number in javascript 19 00:01:26,910 --> 00:01:29,880 by default is a 64 bit float, 20 00:01:29,910 --> 00:01:35,970 so if you want to store it as bigger decimal, you will need to convert it or not convert it but create 21 00:01:35,970 --> 00:01:38,010 such an object with that constructor, 22 00:01:38,010 --> 00:01:43,210 the same exists for 32 bit integers and for longs which are 64 bit integers. 23 00:01:43,230 --> 00:01:46,310 So this is also useful if you want to find out what's in there, 24 00:01:46,410 --> 00:01:49,340 how could I possibly get such a decimal, 25 00:01:49,380 --> 00:01:54,880 well the API reference should help you. But we don't need to dive into that right now, 26 00:01:54,960 --> 00:01:57,020 we just need to install the driver 27 00:01:57,210 --> 00:02:03,390 and as you can see with nodejs, this is the command we have to execute in our project folder to install 28 00:02:03,480 --> 00:02:04,270 the official 29 00:02:04,270 --> 00:02:05,510 mongodb driver. 30 00:02:05,820 --> 00:02:07,450 So we can just comment this 31 00:02:07,860 --> 00:02:13,570 and then in here in our project, I'll open the integrated terminal which is integrated into Visual 32 00:02:13,570 --> 00:02:14,290 Studio Code, 33 00:02:14,370 --> 00:02:18,120 you'll find it under terminal here, new terminal 34 00:02:18,540 --> 00:02:24,270 and this is simply the normal command prompt or terminal you have on your operating system, just already 35 00:02:24,290 --> 00:02:27,770 navigated into this project folder which is great of course. 36 00:02:28,050 --> 00:02:33,240 So I'll paste this command in here and this will now install mongodb in this project, so that I 37 00:02:33,240 --> 00:02:36,290 can use it from inside this project. 38 00:02:36,350 --> 00:02:38,910 Now with that installed, we will be able to use it. 39 00:02:38,910 --> 00:02:45,320 Now one important note, it's the nodejs driver and if you remember our documentation, 40 00:02:45,360 --> 00:02:47,980 there was no reactjs driver, 41 00:02:48,030 --> 00:02:55,530 the reason for that is that you never connect to mongodb through the official drivers directly in your 42 00:02:55,530 --> 00:02:57,030 client side applications, 43 00:02:57,030 --> 00:03:04,470 so in your angular, react or vue user interfaces, you never put your database connection code in there 44 00:03:04,770 --> 00:03:10,650 because you will expose your credentials there to the user which you don't want. On node which runs on a 45 00:03:10,650 --> 00:03:13,600 server and is inaccessible by the user, 46 00:03:13,620 --> 00:03:19,980 these credentials are secure and I will show you what I mean real quick. If we have a look at our running 47 00:03:19,980 --> 00:03:25,920 application and you have a look at the developer tools which you can open by right clicking and inspecting 48 00:03:26,040 --> 00:03:30,430 in Chrome, in these developer tools here, 49 00:03:30,750 --> 00:03:39,240 this is the html code but if you click on sources here, you will actually be able to access the entire 50 00:03:39,240 --> 00:03:43,860 javascript source code that makes up the frontend part of this application, 51 00:03:43,890 --> 00:03:45,930 so the react applications code. 52 00:03:46,230 --> 00:03:54,900 You can access it here under source and here we have our react code and if you had the logic to connect 53 00:03:54,900 --> 00:03:56,740 to mongodb in here, 54 00:03:56,940 --> 00:03:59,830 well then every user using your website can see that 55 00:03:59,900 --> 00:04:01,740 and that's not a security issue, 56 00:04:01,740 --> 00:04:04,330 that's just how frontend javascript works. 57 00:04:04,560 --> 00:04:07,010 It's readable by your users, 58 00:04:07,130 --> 00:04:13,970 therefore the connection logic and the entire interaction logic has to live in the nodejs part, so 59 00:04:13,970 --> 00:04:21,000 on the server. Now there is an alternative which we'll learn about in the stitch module which gives you 60 00:04:21,150 --> 00:04:22,790 a different way of working with 61 00:04:22,800 --> 00:04:23,400 mongodb 62 00:04:23,490 --> 00:04:28,480 but there in the end, it'll still be such that no credentials are exposed in the code 63 00:04:28,500 --> 00:04:30,150 and for now, we don't have to worry about that 64 00:04:30,170 --> 00:04:32,090 other alternative, here 65 00:04:32,110 --> 00:04:33,260 this is how it is, 66 00:04:33,330 --> 00:04:38,800 you must not put your mongodb data, your credentials into this frontend code. 67 00:04:39,150 --> 00:04:45,510 So that is why there is no reactjs driver and no angular and vue or in general, frontend javascript 68 00:04:45,510 --> 00:04:46,170 driver 69 00:04:46,170 --> 00:04:51,090 but why we use the nodejs driver. And with all that out of the way, in the next lexture 70 00:04:51,140 --> 00:04:54,400 let's finally connect our backend here to mongodb.