WEBVTT 0 00:00.480 --> 00:00.780 All right. 1 00:00.780 --> 00:07.530 So first things first. Let's first install MongoDB onto our local system so that we can actually 2 00:07.530 --> 00:08.850 start using it. 3 00:09.210 --> 00:16.860 So if you head over to mongodb.com and just click on get MongoDB then this should take you to 4 00:16.920 --> 00:23.760 the downloads page. And you can see that they have three options for you to choose from: cloud which is 5 00:23.820 --> 00:25.110 MongoDB Atlas 6 00:25.230 --> 00:30.700 and this is what we'll explore a little bit later on when we deploy our application. 7 00:30.840 --> 00:38.820 But for now we need to click on servers and we're going to choose the free community server and make 8 00:38.820 --> 00:44.040 sure that you've got your version selected as current release. The development release is kind of like 9 00:44.040 --> 00:50.280 the beta version and then there's previous versions which are a little bit older which still work just 10 00:50.280 --> 00:56.080 fine but at the time when you're watching this video the current release might no longer be 4.0.3 11 00:56.080 --> 01:02.340 but I still want you to choose the current release because we will be keeping the videos up to date 12 01:02.610 --> 01:05.980 so that you'll be able to work with the latest versions. 13 01:06.300 --> 01:08.850 And then it's automatically detected that 14 01:08.930 --> 01:10.870 I am running on a Mac. 15 01:10.950 --> 01:17.070 Now we're ready to go ahead and click download and it's not too large a file so it should be done pretty 16 01:17.070 --> 01:17.870 quickly. 17 01:18.180 --> 01:24.190 Now if you open up your Downloads folder you should see that compressed file that we just downloaded. 18 01:24.570 --> 01:29.150 And this is what we'll need to get MongoDB working on our local system. 19 01:29.160 --> 01:36.590 So now just double click on it to extract it and we can delete the tgz file that we initially had. 20 01:36.900 --> 01:41.610 This is going to allow us to use MongoDB on our local system. 21 01:41.640 --> 01:45.880 Now there's a couple more things that we have to do in order to get it to work. 22 01:46.410 --> 01:52.140 And if you scroll down here, you can see there's this part where it says Quick Start Guide. And there's 23 01:52.140 --> 01:57.450 a few things here that we still need to do in order to get set up with MongoDB. 24 01:57.810 --> 02:03.930 So on this page if you scroll down a little bit up to the point where it says installing MongoDB community 25 02:03.930 --> 02:06.860 edition manually, we've already done step 1. 26 02:06.860 --> 02:11.590 We've really downloaded the tarball and we've extracted the files. 27 02:11.760 --> 02:14.190 So now we're on to step 4. 28 02:15.310 --> 02:17.660 Not quite sure where it jumps from 2 to 4. 29 02:17.980 --> 02:25.120 But either way now we have to ensure that the binaries are in a directory listed in your PATH environment 30 02:25.300 --> 02:26.200 variable. 31 02:26.410 --> 02:31.480 Ok so this is a little bit confusing but I'll walk you through it step by step. 32 02:31.480 --> 02:38.380 All right so now that we've extracted the files we're going to open up a new terminal using hyper and 33 02:38.380 --> 02:45.970 then we're going to type sudo mv and we're going to use this command to move our existing file currently 34 02:46.030 --> 02:52.660 inside our downloads folder to a location that will be in the root of our computers so that all users 35 02:52.750 --> 02:54.300 will be able to access it. 36 02:54.310 --> 02:58.810 So we're going to specify what it is that we want to move first and then we're going to add a space 37 02:59.110 --> 03:06.340 and then we're going to specify where we want to move it. And the location is going to be / user 38 03:06.400 --> 03:11.480 'usr' /local/mongodb. 39 03:11.500 --> 03:17.470 And this is all lowercase and it's really really important that you check that you've got that first 40 03:17.470 --> 03:22.170 forward slash there before the user and that you've spelt everything correctly. 41 03:22.390 --> 03:26.390 Otherwise this will not work and it will have more issues down the line. 42 03:26.410 --> 03:33.720 So all we did was we typed sudo move and then we clicked and dragged the location of our current MongoDB 43 03:33.730 --> 03:35.010 binary 44 03:35.110 --> 03:40.930 and so that's inputted that entire path in order to get to that file. 45 03:40.930 --> 03:47.290 Now if we hit enter it will ask us for our password because we're using that sudo there which is super 46 03:47.290 --> 03:48.100 user do. 47 03:48.160 --> 03:50.180 So we need admin privileges. 48 03:50.290 --> 03:56.770 So just go ahead and type the password that you normally use to log on to your Mac under your current 49 03:56.800 --> 03:58.180 user name. 50 03:58.180 --> 04:00.070 So for me that's angelayu. 51 04:00.300 --> 04:02.490 And then go ahead and hit enter. 52 04:02.560 --> 04:08.110 Now when you are typing that password you're not going to see any asterisks or anything move. 53 04:08.110 --> 04:11.290 So just make sure that you actually type it out correctly. 54 04:11.290 --> 04:16.030 And if you get it wrong it'll just prompt you to type it again and you'll just have to do that blind. 55 04:16.120 --> 04:21.220 But once you're done you should get back your prompt which is your user name and the dollar sign which 56 04:21.220 --> 04:24.010 means that you're ready to go for your next command. 57 04:25.480 --> 04:29.400 So now we're going to just check to make sure that it did get moved there. 58 04:29.410 --> 04:38.350 So we're going to type open /usr/local/mongodb just to open up that 59 04:38.350 --> 04:39.760 folder inside Finder. 60 04:39.760 --> 04:40.450 We can see 61 04:40.480 --> 04:41.050 Oh yes 62 04:41.080 --> 04:47.140 all of those files all of those binaries have indeed been moved into a folder called mongodb inside 63 04:47.140 --> 04:50.630 something called local inside something called user. 64 04:50.710 --> 04:57.970 And you can see this user is actually a little bit of a light colored blue for its folder icon and this 65 04:57.970 --> 04:59.560 is because it's normally hidden. 66 04:59.740 --> 05:04.380 So unless when we were using this command we wouldn't normally be able to navigate here. 67 05:04.780 --> 05:10.960 All right so now that we confirmed that everything has been moved correctly, the next step is to add 68 05:11.050 --> 05:14.710 the MongoDB binaries to something called environment variables. 69 05:14.980 --> 05:18.030 And this is basically this step here. 70 05:18.310 --> 05:22.440 And we basically need to tell our Mac when it starts up 71 05:22.570 --> 05:24.670 what is the file path to access our 72 05:24.730 --> 05:30.690 MongoDB. In order to do this we're going to make sure that we're in our home folder. 73 05:30.820 --> 05:37.860 So if you're not sure just type cd ~ and that will take you to your home folder which is here. 74 05:38.200 --> 05:43.930 And you could also just write 'pwd' which is print working directory to make sure that you are inside 75 05:43.980 --> 05:50.860 /usr/your current user name because it is at this location that we're going to create 76 05:50.890 --> 05:56.430 a new file and this file is going to be called .bash 77 05:57.310 --> 06:01.920 _profile and you're going to go ahead and hit enter. 78 06:02.250 --> 06:09.390 So now if we do an ls -a you should see that file that we created just now inside the list of hidden 79 06:09.390 --> 06:09.770 files 80 06:09.810 --> 06:14.670 and that's what that little dot means it just means that it's a hidden file where normally if you just 81 06:14.670 --> 06:19.650 hit open at this location you shouldn't be able to see it. 82 06:20.220 --> 06:25.110 OK so now that we've done that, the next step is we're going to edit that file and we're going to use 83 06:25.200 --> 06:28.050 a editor on the command line called vim. 84 06:28.080 --> 06:38.100 So we're going to say vim .bash_profile to open this file that we just created inside 85 06:38.150 --> 06:39.000 vim. 86 06:39.090 --> 06:46.140 Now vim is notorious for being difficult to work with because it doesn't have a graphical user interface, 87 06:46.140 --> 06:48.100 it doesn't have buttons for you to click on. 88 06:48.180 --> 06:50.840 It just has a whole bunch of text commands. 89 06:51.000 --> 06:56.520 And the first thing you have to overcome to actually be able to even write anything inside vim is figure 90 06:56.520 --> 07:01.530 out how you get into insert mode because at the moment you might not even be able to start typing. 91 07:01.540 --> 07:06.000 So in order to get into the insert mode, all you have to do is hit i 92 07:06.060 --> 07:10.190 and this takes you into insert mode as it's shown down here. 93 07:10.530 --> 07:12.630 And now we can start typing. 94 07:12.810 --> 07:26.510 So what we want to type in here is export PATH=$PATH:/usr/ 95 07:26.510 --> 07:32.180 local/mongodb/bin. 96 07:32.380 --> 07:38.370 If this is a bit painful for you to type or you just wanted a guide on how to do this 97 07:38.500 --> 07:44.290 then remember you can always head over to our blog post which are how to install MongoDB on Mac 98 07:44.470 --> 07:47.500 which is linked to in the resources page. 99 07:47.500 --> 07:52.660 So now if you just go ahead and copy this line inside 100 07:52.690 --> 07:54.760 step 4 101 07:54.890 --> 08:00.020 and now we just have to copy this line and you can simply paste it into vim if you wish. 102 08:00.280 --> 08:05.290 So essentially once we've done that and we're happy with this being spelt exactly correct 103 08:05.290 --> 08:10.830 and again if you're not sure and you have any problems then just try and paste that in. 104 08:10.900 --> 08:15.910 The next thing we're going to do is we're going to exit insert mode which we'll do with the ESC key 105 08:17.230 --> 08:22.970 and now we have the opportunity to save and exit vim which again is a bit tricky. 106 08:23.020 --> 08:30.970 We have to type :wq! and this will just save what we've currently 107 08:30.970 --> 08:32.990 got and quit vim. 108 08:33.010 --> 08:39.610 So now when we hit enter we should be back on our familiar command line and our bash_profile should have 109 08:39.610 --> 08:40.710 been edited. 110 08:41.660 --> 08:49.010 The next step is we're going to create a folder on our computer where we will store all of our databases. 111 08:49.130 --> 08:54.770 So we're going to simply just copy this command make directory at the root path which is what that forward 112 08:54.770 --> 08:57.850 slash means and then create a folder called data 113 08:57.860 --> 09:02.870 ff it doesn't exist and inside that folder create one called db. And that p flag 114 09:02.870 --> 09:08.450 just makes sure that we create all of the folders that we require all in the same go instead of creating 115 09:08.450 --> 09:11.810 data and cding into data and then creating db. 116 09:11.840 --> 09:14.300 So it was just a little bit of a shortcut. 117 09:14.420 --> 09:21.620 So we're going to go ahead and copy and paste that into our command line and hit enter and it doesn't 118 09:21.620 --> 09:24.880 actually matter where you are in your command line. 119 09:24.920 --> 09:30.260 You can be at your home folder or you can be anywhere else because this forward slash that starts 120 09:30.260 --> 09:35.990 this line off indicates that we should go to the root or the Macintosh hard drive and then create our 121 09:35.990 --> 09:41.870 data folder there. Now that we've created that folder there if you wanted to just check you can always say 122 09:41.930 --> 09:49.460 open /data/db and that will open it inside our Finder and you can see we've created 123 09:49.460 --> 09:51.500 two new folders in one go 124 09:51.500 --> 09:53.050 using that line there. 125 09:53.330 --> 10:00.350 All right so now that we're done here the next thing is to set permissions for that data directory so 126 10:00.350 --> 10:04.420 that the current user can have read and write permissions. 127 10:04.460 --> 10:09.070 And before we do that you first want to know what your current user name is. 128 10:09.080 --> 10:15.320 So it's pretty obvious if you just look at the prompt, the part before the dollar sign is basically your 129 10:15.320 --> 10:20.960 username that you want to be able to set to have read and write privileges on those new folders that 130 10:20.960 --> 10:22.030 we created. 131 10:22.040 --> 10:24.280 But if you're ever unsure you can also just type 132 10:24.280 --> 10:25.720 whoami 133 10:25.730 --> 10:26.830 into the command line and 134 10:26.840 --> 10:29.470 it'll tell you this is your username. 135 10:29.840 --> 10:33.640 So now that we've got our user name we're going to set those privileges so 136 10:33.680 --> 10:39.320 we're going to write sudo code to invoke our admin privileges and then we're going to write chown 137 10:39.350 --> 10:46.820 so 'chown' and then we're going to write our username which is what I got here after I typed 138 10:46.820 --> 10:47.690 in who am I. 139 10:47.810 --> 10:54.530 So for me it's angelayu and then I'm going to type the directory path that I want to own which is 140 10:54.530 --> 10:58.830 going to be /data/db. 141 10:58.910 --> 11:05.780 So now my current user angelayu actually has read and write admin privileges to that db folder 142 11:06.170 --> 11:10.160 and I'll be able to create databases in there, read to it, write to it 143 11:10.160 --> 11:10.900 etc. 144 11:11.120 --> 11:16.720 So now once I hit enter it will ask me for my password again which I'll just type in. 145 11:17.180 --> 11:19.310 And now we should be good to go. 146 11:19.310 --> 11:26.630 Now before we test it, the first thing to do is to simply quit the terminal. And we're going to open up 147 11:26.690 --> 11:29.570 a new fresh instance. 148 11:31.430 --> 11:38.150 And here we're going to type mongo --version and when we hit enter 149 11:38.210 --> 11:43.850 if you get something that looks like this where it tells you MongoDB shell version is 4.0.3 150 11:44.210 --> 11:51.070 then that means that everything is all set up and you are ready to go and proceed to the next step where 151 11:51.090 --> 11:54.000 I will learn all about MongoDB. 152 11:54.000 --> 12:00.590 Now if at this stage you get something like bash mongo not found then it means that there might have 153 12:00.590 --> 12:05.560 been something that would have gone wrong in the steps that led to this point. 154 12:05.600 --> 12:13.480 So it might be worth just reviewing the steps again in the blog post and just go ahead and step by step 155 12:13.490 --> 12:21.680 confirm that everything's been done to the exact spelling and exact casing and just make sure that you 156 12:21.680 --> 12:23.900 haven't missed out any steps as well. 157 12:24.290 --> 12:26.480 But if you've gotten to this stage then 158 12:26.510 --> 12:31.520 well-done congratulations. You've finally managed to install MongoDB on your local system and you are 159 12:31.520 --> 12:34.060 ready to proceed to the next step.