1 00:00:01,410 --> 00:00:03,240 In this video you are gonna learn how 2 00:00:03,240 --> 00:00:07,040 to install MongoDB on a Windows computer, 3 00:00:07,040 --> 00:00:08,690 so if you're using a Mac 4 00:00:08,690 --> 00:00:11,780 please just mark this video as completed. 5 00:00:11,780 --> 00:00:15,920 Now since I personally don't own any Windows computer and 6 00:00:15,920 --> 00:00:18,170 this installation involves a couple of 7 00:00:18,170 --> 00:00:19,770 Windows specific steps, 8 00:00:19,770 --> 00:00:22,620 I asked my teaching assistant Aleksander, 9 00:00:22,620 --> 00:00:24,730 to take you through the process. 10 00:00:24,730 --> 00:00:27,173 So everyone say hi to Aleksander. 11 00:00:28,070 --> 00:00:30,250 Hello guys my name is Aleksander and 12 00:00:30,250 --> 00:00:31,930 in this lecture I will show you how 13 00:00:31,930 --> 00:00:34,693 to install MongoDB on your Windows machine. 14 00:00:35,610 --> 00:00:37,510 First you need to open your browser and 15 00:00:37,510 --> 00:00:39,970 go to the MongoDB.com website, 16 00:00:39,970 --> 00:00:41,720 you can see the address right here. 17 00:00:43,270 --> 00:00:45,420 Then you need to click on products and 18 00:00:45,420 --> 00:00:47,783 choose MongoDB server, okay? 19 00:00:49,340 --> 00:00:51,483 Now click on this green download button. 20 00:00:52,570 --> 00:00:55,183 And once again choose server from here. 21 00:00:57,640 --> 00:00:59,525 Okay, now we want to install this 22 00:00:59,525 --> 00:01:02,330 MongoDB Community Server and 23 00:01:02,330 --> 00:01:03,980 we have a couple of options here, 24 00:01:05,230 --> 00:01:07,200 so please choose the current release, 25 00:01:07,200 --> 00:01:12,200 which at this point of time is the 4.0.9, okay? 26 00:01:12,500 --> 00:01:15,500 As the operating system please choose Windows, 27 00:01:15,500 --> 00:01:19,610 and I would just stick with this default MSI package, okay? 28 00:01:19,610 --> 00:01:21,540 So after setting this up you can just hit 29 00:01:21,540 --> 00:01:23,440 this download button, or 30 00:01:23,440 --> 00:01:25,050 in case it doesn't work for you, 31 00:01:25,050 --> 00:01:27,640 just copy the link below and 32 00:01:27,640 --> 00:01:30,433 paste it in the address bar, okay? 33 00:01:31,940 --> 00:01:34,610 So now we should see this pop-up that will ask you if 34 00:01:34,610 --> 00:01:36,090 you want to save this file, 35 00:01:36,090 --> 00:01:38,320 just click save file and 36 00:01:38,320 --> 00:01:40,083 it should start downloading okay? 37 00:01:41,240 --> 00:01:42,730 So I will just stop this because 38 00:01:42,730 --> 00:01:44,173 I already have this file. 39 00:01:45,220 --> 00:01:48,230 Okay? But after downloading it you can just 40 00:01:48,230 --> 00:01:50,160 close the browser, 41 00:01:50,160 --> 00:01:51,763 open your File Manager, 42 00:01:53,610 --> 00:01:56,530 go to Downloads. 43 00:01:56,530 --> 00:02:01,070 And you can see the installer is already there, all right? 44 00:02:01,070 --> 00:02:02,413 So double click on that, 45 00:02:04,050 --> 00:02:07,370 and now you should see the Setup Wizard okay? 46 00:02:07,370 --> 00:02:09,070 Click next, 47 00:02:09,070 --> 00:02:11,300 accept the license, 48 00:02:11,300 --> 00:02:14,093 and click to install this complete version, okay? 49 00:02:15,225 --> 00:02:16,600 And now it will ask you if 50 00:02:16,600 --> 00:02:18,920 you want to install MongoDB as a service, 51 00:02:18,920 --> 00:02:20,330 which basically means that 52 00:02:20,330 --> 00:02:23,530 Mongo's server will run in the background, 53 00:02:23,530 --> 00:02:26,650 so you can check this, click next. 54 00:02:26,650 --> 00:02:29,560 It will also ask you to install MongoDB Compass, 55 00:02:29,560 --> 00:02:32,360 which is the graphical user interface, 56 00:02:32,360 --> 00:02:34,623 so we can also check this and click next. 57 00:02:35,990 --> 00:02:37,823 And now just click install, 58 00:02:39,140 --> 00:02:42,040 and you may see some windows pop-up that 59 00:02:42,040 --> 00:02:44,820 will ask you if you want to allow this App to 60 00:02:44,820 --> 00:02:47,540 be installed on your device, okay? 61 00:02:47,540 --> 00:02:49,713 So in that case just click yes. 62 00:02:50,970 --> 00:02:53,330 And now it should start the installation process, 63 00:02:53,330 --> 00:02:55,733 it will take about five to ten minutes, 64 00:02:56,870 --> 00:03:00,143 So I'll be right back to you after the installation. 65 00:03:02,040 --> 00:03:06,123 All right, now just let this compass install, 66 00:03:09,740 --> 00:03:12,663 okay you can see the shortcut right here, 67 00:03:14,190 --> 00:03:17,400 and this is basically the compass community window, 68 00:03:17,400 --> 00:03:19,083 so you can close this, 69 00:03:20,060 --> 00:03:21,463 click this finish button, 70 00:03:23,530 --> 00:03:26,210 and now we have two more things to do. 71 00:03:26,210 --> 00:03:28,870 First we need to create a directory in 72 00:03:28,870 --> 00:03:31,550 which MongoDB will store our data. 73 00:03:31,550 --> 00:03:34,363 For this please open your file manager once again, 74 00:03:35,380 --> 00:03:38,120 and go to the disk where MongoDB was installed, 75 00:03:38,120 --> 00:03:40,423 so in my case it's Local Disk C. 76 00:03:41,610 --> 00:03:44,330 Here create a directory called data, 77 00:03:44,330 --> 00:03:45,910 so right click here, 78 00:03:45,910 --> 00:03:47,350 new 79 00:03:47,350 --> 00:03:48,183 folder 80 00:03:48,183 --> 00:03:50,403 and call this folder Data, okay? 81 00:03:52,500 --> 00:03:54,400 Now inside this data folder, 82 00:03:54,400 --> 00:03:56,633 create another one called DB. 83 00:03:58,550 --> 00:04:01,170 All right, so this is the place where 84 00:04:01,170 --> 00:04:04,320 MongoDB will store our databases. 85 00:04:04,320 --> 00:04:06,020 Now let me quickly show you that 86 00:04:06,020 --> 00:04:07,830 MongoDB actually works, 87 00:04:07,830 --> 00:04:09,593 so I'm going to Local Disk C, 88 00:04:11,100 --> 00:04:12,173 Program Files, 89 00:04:13,280 --> 00:04:14,963 find MongoDB here, 90 00:04:16,350 --> 00:04:17,610 go to server, 91 00:04:17,610 --> 00:04:22,280 4.0, and we are interested in this bin directory, okay? 92 00:04:22,280 --> 00:04:24,500 So we can see there is a lot of files here, 93 00:04:24,500 --> 00:04:29,330 but basically we are interested in this MongoD file, 94 00:04:29,330 --> 00:04:31,450 which is Mongo's server and 95 00:04:31,450 --> 00:04:35,363 in this Mongo.exe file which is Mongo Shell, okay? 96 00:04:36,340 --> 00:04:38,610 So let me just copy the path from here and 97 00:04:38,610 --> 00:04:40,023 open my console, 98 00:04:41,370 --> 00:04:43,250 and by the way I'm using PowerShell but 99 00:04:43,250 --> 00:04:45,480 you can also use the Command Prompt, okay? 100 00:04:45,480 --> 00:04:47,030 It doesn't matter in this case. 101 00:04:49,420 --> 00:04:51,500 So I'm using the CD commands to 102 00:04:51,500 --> 00:04:53,670 go to this directory, 103 00:04:53,670 --> 00:04:55,970 you can also write this DIR command to 104 00:04:55,970 --> 00:04:57,590 list all the files, 105 00:04:57,590 --> 00:05:00,420 and if you compare them you can see that 106 00:05:00,420 --> 00:05:01,760 all these files are the same, okay? 107 00:05:01,760 --> 00:05:03,623 So we are in the same bin directory. 108 00:05:05,310 --> 00:05:08,833 And now let me just run this MongoD server, 109 00:05:10,090 --> 00:05:13,823 so Mongod.exe, you can hit tab to auto complete this, 110 00:05:14,900 --> 00:05:19,807 and I'm just hitting Enter and you can see that 111 00:05:19,807 --> 00:05:22,733 the server is starting, okay? 112 00:05:24,450 --> 00:05:27,150 So if you take a look at this line you can see that 113 00:05:27,150 --> 00:05:31,510 it's waiting for connections on port 27017, 114 00:05:31,510 --> 00:05:34,360 so we've basically started a server and 115 00:05:34,360 --> 00:05:37,530 now we need a shell to connect to the server to 116 00:05:37,530 --> 00:05:40,940 be able to manipulate our databases, okay? 117 00:05:40,940 --> 00:05:43,330 So we'll be able to create databases, 118 00:05:43,330 --> 00:05:45,480 delete databases, 119 00:05:45,480 --> 00:05:47,560 to records, etc. 120 00:05:47,560 --> 00:05:48,393 All right, 121 00:05:49,590 --> 00:05:51,620 I will just open another PowerShell window to 122 00:05:51,620 --> 00:05:52,987 demonstrate it to you. 123 00:05:55,900 --> 00:05:59,860 And just CD to the same bin directory, 124 00:05:59,860 --> 00:06:03,010 but now run this Mongo.exe, okay? 125 00:06:03,010 --> 00:06:04,653 So this is the Mongo Shell, 126 00:06:05,980 --> 00:06:10,450 and you can see that we've automatically connected to 127 00:06:10,450 --> 00:06:12,400 the same port okay? 128 00:06:12,400 --> 00:06:16,680 And now I would just run the DB command 129 00:06:16,680 --> 00:06:21,680 and I should get the test database in return, okay? 130 00:06:21,820 --> 00:06:23,220 And that's right. 131 00:06:23,220 --> 00:06:26,380 So now you see that everything works, okay? 132 00:06:26,380 --> 00:06:28,750 In this PowerShell we are running the server, 133 00:06:28,750 --> 00:06:32,320 in this PowerShell window we've connected to the server, 134 00:06:32,320 --> 00:06:33,153 okay? 135 00:06:34,240 --> 00:06:37,633 And now we can just close this process using Control + C. 136 00:06:40,160 --> 00:06:44,253 I will also close the server, okay. 137 00:06:46,390 --> 00:06:49,250 And there is actually one more thing to do, 138 00:06:49,250 --> 00:06:54,250 so what if I would like to run this Mongo server from 139 00:06:54,910 --> 00:06:56,920 another directory, okay? 140 00:06:56,920 --> 00:06:58,270 Let me just show it to you. 141 00:07:00,120 --> 00:07:02,633 I will open another PowerShell window, 142 00:07:04,050 --> 00:07:07,380 and now we can see that I'm currently in my user directory, 143 00:07:07,380 --> 00:07:10,540 so I'm in C:\Users\Aleksander and 144 00:07:10,540 --> 00:07:15,290 I want to open MongoDB server from here, 145 00:07:15,290 --> 00:07:17,140 let me just write this command, 146 00:07:17,140 --> 00:07:18,420 so Mongod.exe 147 00:07:19,740 --> 00:07:21,480 and there is an error, okay? 148 00:07:21,480 --> 00:07:25,230 So it says "The term mongod.exe is not recognized as 149 00:07:25,230 --> 00:07:27,200 the name of cmdLet, function, 150 00:07:27,200 --> 00:07:30,257 script file, or operable program." 151 00:07:31,140 --> 00:07:34,510 So basically Windows don't know where to look for 152 00:07:34,510 --> 00:07:36,840 this MongoD.exe file, okay? 153 00:07:36,840 --> 00:07:39,560 So it thinks this file should be in 154 00:07:39,560 --> 00:07:41,140 my user directory, 155 00:07:41,140 --> 00:07:43,020 but of course this file doesn't exist here, 156 00:07:43,020 --> 00:07:46,720 because it comes from MongoDB bin directory. 157 00:07:46,720 --> 00:07:50,010 So we need to find a way to tell Windows to 158 00:07:50,010 --> 00:07:52,070 look for this file in that 159 00:07:52,070 --> 00:07:53,680 bin directory, okay? 160 00:07:53,680 --> 00:07:58,120 And we can actually do this using system variables. 161 00:07:58,120 --> 00:08:00,083 So let's close these windows for now, 162 00:08:01,300 --> 00:08:04,323 and I will open settings, 163 00:08:06,920 --> 00:08:10,863 And here in the search bar just write Env, okay? 164 00:08:12,010 --> 00:08:15,453 And click on this "Edit the system environment variables" 165 00:08:17,600 --> 00:08:19,560 so now you should see this small window, 166 00:08:19,560 --> 00:08:20,970 it's called System Properties, 167 00:08:20,970 --> 00:08:23,210 we are in the Advanced tab, 168 00:08:23,210 --> 00:08:24,727 and here just click on this 169 00:08:24,727 --> 00:08:27,063 Environment Variables button, okay? 170 00:08:28,810 --> 00:08:32,040 And we are interested in the system variables, 171 00:08:32,040 --> 00:08:33,730 Path variable, okay? 172 00:08:33,730 --> 00:08:36,850 Click edit, and you can see that 173 00:08:36,850 --> 00:08:38,770 there is a couple of Paths added here, 174 00:08:38,770 --> 00:08:42,430 for example, I have added NodeJS and Git, 175 00:08:42,430 --> 00:08:46,040 so I'm able to run Node from anywhere, 176 00:08:46,040 --> 00:08:48,920 and we will add MongoDB here as well. 177 00:08:48,920 --> 00:08:51,093 So let me just copy the Path from here, 178 00:08:52,890 --> 00:08:55,303 so this is this bin directory okay. 179 00:08:56,540 --> 00:08:59,770 And I will just create another variable here and 180 00:08:59,770 --> 00:09:00,820 paste this Path here. 181 00:09:01,690 --> 00:09:03,600 Now we can just click Okay, 182 00:09:03,600 --> 00:09:04,740 once again click Okay, 183 00:09:04,740 --> 00:09:06,040 you can close this window, 184 00:09:07,100 --> 00:09:11,123 and let's test it in PowerShell, okay? 185 00:09:13,150 --> 00:09:17,310 So you can see that I'm currently in my user directory, 186 00:09:17,310 --> 00:09:20,923 and I will run MongoD.exe once again. 187 00:09:23,540 --> 00:09:27,640 And you can see that everything works just fine, okay? 188 00:09:27,640 --> 00:09:30,780 So the server is running on the same port as before 189 00:09:31,940 --> 00:09:34,293 and it's ready to use, all right? 190 00:09:35,290 --> 00:09:36,460 So you can close this, 191 00:09:38,100 --> 00:09:39,890 and this is all. 192 00:09:39,890 --> 00:09:42,930 So we've installed MongoDB and MongoDB Compass on 193 00:09:42,930 --> 00:09:44,760 our Windows computer, 194 00:09:44,760 --> 00:09:47,470 we've created a directory called Data to 195 00:09:47,470 --> 00:09:49,710 store our databases, 196 00:09:49,710 --> 00:09:52,470 and we've also added MongoDB to the Path, 197 00:09:52,470 --> 00:09:55,580 so we are able to run MongoDB commands from 198 00:09:55,580 --> 00:09:56,963 anywhere in our system.