0 1 00:00:00,480 --> 00:00:00,780 All right. 1 2 00:00:00,780 --> 00:00:07,530 So first things first. Let's first install MongoDB onto our local system so that we can actually 2 3 00:00:07,530 --> 00:00:08,850 start using it. 3 4 00:00:09,210 --> 00:00:16,860 So if you head over to mongodb.com and just click on get MongoDB then this should take you to 4 5 00:00:16,920 --> 00:00:23,760 the downloads page. And you can see that they have three options for you to choose from: cloud which is 5 6 00:00:23,820 --> 00:00:25,110 MongoDB Atlas 6 7 00:00:25,230 --> 00:00:30,700 and this is what we'll explore a little bit later on when we deploy our application. 7 8 00:00:30,840 --> 00: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 9 00:00:38,820 --> 00:00:44,040 sure that you've got your version selected as current release. The development release is kind of like 9 10 00:00:44,040 --> 00:00:50,280 the beta version and then there's previous versions which are a little bit older which still work just 10 11 00:00:50,280 --> 00: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 12 00:00:56,080 --> 00:01:02,340 but I still want you to choose the current release because we will be keeping the videos up to date 12 13 00:01:02,610 --> 00:01:05,980 so that you'll be able to work with the latest versions. 13 14 00:01:06,300 --> 00:01:08,850 And then it's automatically detected that 14 15 00:01:08,930 --> 00:01:10,870 I am running on a Mac. 15 16 00:01:10,950 --> 00: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 17 00:01:17,070 --> 00:01:17,870 quickly. 17 18 00:01:18,180 --> 00:01:24,190 Now if you open up your Downloads folder you should see that compressed file that we just downloaded. 18 19 00:01:24,570 --> 00:01:29,150 And this is what we'll need to get MongoDB working on our local system. 19 20 00:01:29,160 --> 00: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 21 00:01:36,900 --> 00:01:41,610 This is going to allow us to use MongoDB on our local system. 21 22 00:01:41,640 --> 00:01:45,880 Now there's a couple more things that we have to do in order to get it to work. 22 23 00:01:46,410 --> 00: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 24 00:01:52,140 --> 00:01:57,450 a few things here that we still need to do in order to get set up with MongoDB. 24 25 00:01:57,810 --> 00: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 26 00:02:03,930 --> 00:02:06,860 edition manually, we've already done step 1. 26 27 00:02:06,860 --> 00:02:11,590 We've really downloaded the tarball and we've extracted the files. 27 28 00:02:11,760 --> 00:02:14,190 So now we're on to step 4. 28 29 00:02:15,310 --> 00:02:17,660 Not quite sure where it jumps from 2 to 4. 29 30 00:02:17,980 --> 00:02:25,120 But either way now we have to ensure that the binaries are in a directory listed in your PATH environment 30 31 00:02:25,300 --> 00:02:26,200 variable. 31 32 00:02:26,410 --> 00:02:31,480 Ok so this is a little bit confusing but I'll walk you through it step by step. 32 33 00:02:31,480 --> 00: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 34 00:02:38,380 --> 00: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 35 00:02:46,030 --> 00:02:52,660 inside our downloads folder to a location that will be in the root of our computers so that all users 35 36 00:02:52,750 --> 00:02:54,300 will be able to access it. 36 37 00:02:54,310 --> 00: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 38 00:02:59,110 --> 00: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 39 00:03:06,400 --> 00:03:11,480 'usr' /local/mongodb. 39 40 00:03:11,500 --> 00:03:17,470 And this is all lowercase and it's really really important that you check that you've got that first 40 41 00:03:17,470 --> 00:03:22,170 forward slash there before the user and that you've spelt everything correctly. 41 42 00:03:22,390 --> 00:03:26,390 Otherwise this will not work and it will have more issues down the line. 42 43 00:03:26,410 --> 00: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 44 00:03:33,730 --> 00:03:35,010 binary 44 45 00:03:35,110 --> 00:03:40,930 and so that's inputted that entire path in order to get to that file. 45 46 00:03:40,930 --> 00: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 47 00:03:47,290 --> 00:03:48,100 user do. 47 48 00:03:48,160 --> 00:03:50,180 So we need admin privileges. 48 49 00:03:50,290 --> 00: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 50 00:03:56,800 --> 00:03:58,180 user name. 50 51 00:03:58,180 --> 00:04:00,070 So for me that's angelayu. 51 52 00:04:00,300 --> 00:04:02,490 And then go ahead and hit enter. 52 53 00:04:02,560 --> 00:04:08,110 Now when you are typing that password you're not going to see any asterisks or anything move. 53 54 00:04:08,110 --> 00:04:11,290 So just make sure that you actually type it out correctly. 54 55 00:04:11,290 --> 00: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 56 00:04:16,120 --> 00: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 57 00:04:21,220 --> 00:04:24,010 means that you're ready to go for your next command. 57 58 00:04:25,480 --> 00:04:29,400 So now we're going to just check to make sure that it did get moved there. 58 59 00:04:29,410 --> 00:04:38,350 So we're going to type open /usr/local/mongodb just to open up that 59 60 00:04:38,350 --> 00:04:39,760 folder inside Finder. 60 61 00:04:39,760 --> 00:04:40,450 We can see 61 62 00:04:40,480 --> 00:04:41,050 Oh yes 62 63 00:04:41,080 --> 00:04:47,140 all of those files all of those binaries have indeed been moved into a folder called mongodb inside 63 64 00:04:47,140 --> 00:04:50,630 something called local inside something called user. 64 65 00:04:50,710 --> 00: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 66 00:04:57,970 --> 00:04:59,560 is because it's normally hidden. 66 67 00:04:59,740 --> 00:05:04,380 So unless when we were using this command we wouldn't normally be able to navigate here. 67 68 00:05:04,780 --> 00:05:10,960 All right so now that we confirmed that everything has been moved correctly, the next step is to add 68 69 00:05:11,050 --> 00:05:14,710 the MongoDB binaries to something called environment variables. 69 70 00:05:14,980 --> 00:05:18,030 And this is basically this step here. 70 71 00:05:18,310 --> 00:05:22,440 And we basically need to tell our Mac when it starts up 71 72 00:05:22,570 --> 00:05:24,670 what is the file path to access our 72 73 00:05:24,730 --> 00:05:30,690 MongoDB. In order to do this we're going to make sure that we're in our home folder. 73 74 00:05:30,820 --> 00: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 75 00:05:38,200 --> 00:05:43,930 And you could also just write 'pwd' which is print working directory to make sure that you are inside 75 76 00:05:43,980 --> 00:05:50,860 /usr/your current user name because it is at this location that we're going to create 76 77 00:05:50,890 --> 00:05:56,430 a new file and this file is going to be called .bash 77 78 00:05:57,310 --> 00:06:01,920 _profile and you're going to go ahead and hit enter. 78 79 00:06:02,250 --> 00: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 80 00:06:09,390 --> 00:06:09,770 files 80 81 00:06:09,810 --> 00: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 82 00:06:14,670 --> 00:06:19,650 hit open at this location you shouldn't be able to see it. 82 83 00:06:20,220 --> 00: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 84 00:06:25,200 --> 00:06:28,050 a editor on the command line called vim. 84 85 00:06:28,080 --> 00:06:38,100 So we're going to say vim .bash_profile to open this file that we just created inside 85 86 00:06:38,150 --> 00:06:39,000 vim. 86 87 00:06:39,090 --> 00:06:46,140 Now vim is notorious for being difficult to work with because it doesn't have a graphical user interface, 87 88 00:06:46,140 --> 00:06:48,100 it doesn't have buttons for you to click on. 88 89 00:06:48,180 --> 00:06:50,840 It just has a whole bunch of text commands. 89 90 00:06:51,000 --> 00:06:56,520 And the first thing you have to overcome to actually be able to even write anything inside vim is figure 90 91 00:06:56,520 --> 00:07:01,530 out how you get into insert mode because at the moment you might not even be able to start typing. 91 92 00:07:01,540 --> 00:07:06,000 So in order to get into the insert mode, all you have to do is hit i 92 93 00:07:06,060 --> 00:07:10,190 and this takes you into insert mode as it's shown down here. 93 94 00:07:10,530 --> 00:07:12,630 And now we can start typing. 94 95 00:07:12,810 --> 00:07:26,510 So what we want to type in here is export PATH=$PATH:/usr/ 95 96 00:07:26,510 --> 00:07:32,180 local/mongodb/bin. 96 97 00:07:32,380 --> 00: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 98 00:07:38,500 --> 00:07:44,290 then remember you can always head over to our blog post which are how to install MongoDB on Mac 98 99 00:07:44,470 --> 00:07:47,500 which is linked to in the resources page. 99 100 00:07:47,500 --> 00:07:52,660 So now if you just go ahead and copy this line inside 100 101 00:07:52,690 --> 00:07:54,760 step 4 101 102 00:07:54,890 --> 00:08:00,020 and now we just have to copy this line and you can simply paste it into vim if you wish. 102 103 00:08:00,280 --> 00:08:05,290 So essentially once we've done that and we're happy with this being spelt exactly correct 103 104 00:08:05,290 --> 00:08:10,830 and again if you're not sure and you have any problems then just try and paste that in. 104 105 00:08:10,900 --> 00: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 106 00:08:17,230 --> 00:08:22,970 and now we have the opportunity to save and exit vim which again is a bit tricky. 106 107 00:08:23,020 --> 00:08:30,970 We have to type :wq! and this will just save what we've currently 107 108 00:08:30,970 --> 00:08:32,990 got and quit vim. 108 109 00:08:33,010 --> 00: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 110 00:08:39,610 --> 00:08:40,710 been edited. 110 111 00:08:41,660 --> 00: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 112 00:08:49,130 --> 00: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 113 00:08:54,770 --> 00:08:57,850 slash means and then create a folder called data 113 114 00:08:57,860 --> 00:09:02,870 ff it doesn't exist and inside that folder create one called db. And that p flag 114 115 00:09:02,870 --> 00: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 116 00:09:08,450 --> 00:09:11,810 data and cding into data and then creating db. 116 117 00:09:11,840 --> 00:09:14,300 So it was just a little bit of a shortcut. 117 118 00:09:14,420 --> 00: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 119 00:09:21,620 --> 00:09:24,880 actually matter where you are in your command line. 119 120 00:09:24,920 --> 00:09:30,260 You can be at your home folder or you can be anywhere else because this forward slash that starts 120 121 00:09:30,260 --> 00:09:35,990 this line off indicates that we should go to the root or the Macintosh hard drive and then create our 121 122 00:09:35,990 --> 00: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 123 00:09:41,930 --> 00:09:49,460 open /data/db and that will open it inside our Finder and you can see we've created 123 124 00:09:49,460 --> 00:09:51,500 two new folders in one go 124 125 00:09:51,500 --> 00:09:53,050 using that line there. 125 126 00:09:53,330 --> 00: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 127 00:10:00,350 --> 00:10:04,420 that the current user can have read and write permissions. 127 128 00:10:04,460 --> 00:10:09,070 And before we do that you first want to know what your current user name is. 128 129 00:10:09,080 --> 00: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 130 00:10:15,320 --> 00:10:20,960 username that you want to be able to set to have read and write privileges on those new folders that 130 131 00:10:20,960 --> 00:10:22,030 we created. 131 132 00:10:22,040 --> 00:10:24,280 But if you're ever unsure you can also just type 132 133 00:10:24,280 --> 00:10:25,720 whoami 133 134 00:10:25,730 --> 00:10:26,830 into the command line and 134 135 00:10:26,840 --> 00:10:29,470 it'll tell you this is your username. 135 136 00:10:29,840 --> 00:10:33,640 So now that we've got our user name we're going to set those privileges so 136 137 00:10:33,680 --> 00:10:39,320 we're going to write sudo code to invoke our admin privileges and then we're going to write chown 137 138 00:10:39,350 --> 00:10:46,820 so 'chown' and then we're going to write our username which is what I got here after I typed 138 139 00:10:46,820 --> 00:10:47,690 in who am I. 139 140 00:10:47,810 --> 00: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 141 00:10:54,530 --> 00:10:58,830 going to be /data/db. 141 142 00:10:58,910 --> 00:11:05,780 So now my current user angelayu actually has read and write admin privileges to that db folder 142 143 00:11:06,170 --> 00:11:10,160 and I'll be able to create databases in there, read to it, write to it 143 144 00:11:10,160 --> 00:11:10,900 etc. 144 145 00:11:11,120 --> 00:11:16,720 So now once I hit enter it will ask me for my password again which I'll just type in. 145 146 00:11:17,180 --> 00:11:19,310 And now we should be good to go. 146 147 00:11:19,310 --> 00: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 148 00:11:26,690 --> 00:11:29,570 a new fresh instance. 148 149 00:11:31,430 --> 00:11:38,150 And here we're going to type mongo --version and when we hit enter 149 150 00:11:38,210 --> 00:11:43,850 if you get something that looks like this where it tells you MongoDB shell version is 4.0.3 150 151 00:11:44,210 --> 00: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 152 00:11:51,090 --> 00:11:54,000 I will learn all about MongoDB. 152 153 00:11:54,000 --> 00:12:00,590 Now if at this stage you get something like bash mongo not found then it means that there might have 153 154 00:12:00,590 --> 00:12:05,560 been something that would have gone wrong in the steps that led to this point. 154 155 00:12:05,600 --> 00: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 156 00:12:13,490 --> 00:12:21,680 confirm that everything's been done to the exact spelling and exact casing and just make sure that you 156 157 00:12:21,680 --> 00:12:23,900 haven't missed out any steps as well. 157 158 00:12:24,290 --> 00:12:26,480 But if you've gotten to this stage then 158 159 00:12:26,510 --> 00:12:31,520 well-done congratulations. You've finally managed to install MongoDB on your local system and you are 159 160 00:12:31,520 --> 00:12:34,060 ready to proceed to the next step.