All right. 1
So first things first. Let's first install MongoDB onto our local system so that we can actually 2
start using it. 3
So if you head over to mongodb.com and just click on get MongoDB then this should take you to 4
the downloads page. And you can see that they have three options for you to choose from: cloud which is 5
MongoDB Atlas 6
and this is what we'll explore a little bit later on when we deploy our application. 7
But for now we need to click on servers and we're going to choose the free community server and make 8
sure that you've got your version selected as current release. The development release is kind of like 9
the beta version and then there's previous versions which are a little bit older which still work just 10
fine but at the time when you're watching this video the current release might no longer be 4.0.3 11
but I still want you to choose the current release because we will be keeping the videos up to date 12
so that you'll be able to work with the latest versions. 13
And then it's automatically detected that 14
I am running on a Mac. 15
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
quickly. 17
Now if you open up your Downloads folder you should see that compressed file that we just downloaded. 18
And this is what we'll need to get MongoDB working on our local system. 19
So now just double click on it to extract it and we can delete the tgz file that we initially had. 20
This is going to allow us to use MongoDB on our local system. 21
Now there's a couple more things that we have to do in order to get it to work. 22
And if you scroll down here, you can see there's this part where it says Quick Start Guide. And there's 23
a few things here that we still need to do in order to get set up with MongoDB. 24
So on this page if you scroll down a little bit up to the point where it says installing MongoDB community 25
edition manually, we've already done step 1. 26
We've really downloaded the tarball and we've extracted the files. 27
So now we're on to step 4. 28
Not quite sure where it jumps from 2 to 4. 29
But either way now we have to ensure that the binaries are in a directory listed in your PATH environment 30
variable. 31
Ok so this is a little bit confusing but I'll walk you through it step by step. 32
All right so now that we've extracted the files we're going to open up a new terminal using hyper and 33
then we're going to type sudo mv and we're going to use this command to move our existing file currently 34
inside our downloads folder to a location that will be in the root of our computers so that all users 35
will be able to access it. 36
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
and then we're going to specify where we want to move it. And the location is going to be / user 38
'usr' /local/mongodb. 39
And this is all lowercase and it's really really important that you check that you've got that first 40
forward slash there before the user and that you've spelt everything correctly. 41
Otherwise this will not work and it will have more issues down the line. 42
So all we did was we typed sudo move and then we clicked and dragged the location of our current MongoDB 43
binary 44
and so that's inputted that entire path in order to get to that file. 45
Now if we hit enter it will ask us for our password because we're using that sudo there which is super 46
user do. 47
So we need admin privileges. 48
So just go ahead and type the password that you normally use to log on to your Mac under your current 49
user name. 50
So for me that's angelayu. 51
And then go ahead and hit enter. 52
Now when you are typing that password you're not going to see any asterisks or anything move. 53
So just make sure that you actually type it out correctly. 54
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
But once you're done you should get back your prompt which is your user name and the dollar sign which 56
means that you're ready to go for your next command. 57
So now we're going to just check to make sure that it did get moved there. 58
So we're going to type open /usr/local/mongodb just to open up that 59
folder inside Finder. 60
We can see 61
Oh yes 62
all of those files all of those binaries have indeed been moved into a folder called mongodb inside 63
something called local inside something called user. 64
And you can see this user is actually a little bit of a light colored blue for its folder icon and this 65
is because it's normally hidden. 66
So unless when we were using this command we wouldn't normally be able to navigate here. 67
All right so now that we confirmed that everything has been moved correctly, the next step is to add 68
the MongoDB binaries to something called environment variables. 69
And this is basically this step here. 70
And we basically need to tell our Mac when it starts up 71
what is the file path to access our 72
MongoDB. In order to do this we're going to make sure that we're in our home folder. 73
So if you're not sure just type cd ~ and that will take you to your home folder which is here. 74
And you could also just write 'pwd' which is print working directory to make sure that you are inside 75
/usr/your current user name because it is at this location that we're going to create 76
a new file and this file is going to be called .bash 77
_profile and you're going to go ahead and hit enter. 78
So now if we do an ls -a you should see that file that we created just now inside the list of hidden 79
files 80
and that's what that little dot means it just means that it's a hidden file where normally if you just 81
hit open at this location you shouldn't be able to see it. 82
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
a editor on the command line called vim. 84
So we're going to say vim .bash_profile to open this file that we just created inside 85
vim. 86
Now vim is notorious for being difficult to work with because it doesn't have a graphical user interface, 87
it doesn't have buttons for you to click on. 88
It just has a whole bunch of text commands. 89
And the first thing you have to overcome to actually be able to even write anything inside vim is figure 90
out how you get into insert mode because at the moment you might not even be able to start typing. 91
So in order to get into the insert mode, all you have to do is hit i 92
and this takes you into insert mode as it's shown down here. 93
And now we can start typing. 94
So what we want to type in here is export PATH=$PATH:/usr/ 95
local/mongodb/bin. 96
If this is a bit painful for you to type or you just wanted a guide on how to do this 97
then remember you can always head over to our blog post which are how to install MongoDB on Mac 98
which is linked to in the resources page. 99
So now if you just go ahead and copy this line inside 100
step 4 101
and now we just have to copy this line and you can simply paste it into vim if you wish. 102
So essentially once we've done that and we're happy with this being spelt exactly correct 103
and again if you're not sure and you have any problems then just try and paste that in. 104
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
and now we have the opportunity to save and exit vim which again is a bit tricky. 106
We have to type :wq! and this will just save what we've currently 107
got and quit vim. 108
So now when we hit enter we should be back on our familiar command line and our bash_profile should have 109
been edited. 110
The next step is we're going to create a folder on our computer where we will store all of our databases. 111
So we're going to simply just copy this command make directory at the root path which is what that forward 112
slash means and then create a folder called data 113
ff it doesn't exist and inside that folder create one called db. And that p flag 114
just makes sure that we create all of the folders that we require all in the same go instead of creating 115
data and cding into data and then creating db. 116
So it was just a little bit of a shortcut. 117
So we're going to go ahead and copy and paste that into our command line and hit enter and it doesn't 118
actually matter where you are in your command line. 119
You can be at your home folder or you can be anywhere else because this forward slash that starts 120
this line off indicates that we should go to the root or the Macintosh hard drive and then create our 121
data folder there. Now that we've created that folder there if you wanted to just check you can always say 122
open /data/db and that will open it inside our Finder and you can see we've created 123
two new folders in one go 124
using that line there. 125
All right so now that we're done here the next thing is to set permissions for that data directory so 126
that the current user can have read and write permissions. 127
And before we do that you first want to know what your current user name is. 128
So it's pretty obvious if you just look at the prompt, the part before the dollar sign is basically your 129
username that you want to be able to set to have read and write privileges on those new folders that 130
we created. 131
But if you're ever unsure you can also just type 132
whoami 133
into the command line and 134
it'll tell you this is your username. 135
So now that we've got our user name we're going to set those privileges so 136
we're going to write sudo code to invoke our admin privileges and then we're going to write chown 137
so 'chown' and then we're going to write our username which is what I got here after I typed 138
in who am I. 139
So for me it's angelayu and then I'm going to type the directory path that I want to own which is 140
going to be /data/db. 141
So now my current user angelayu actually has read and write admin privileges to that db folder 142
and I'll be able to create databases in there, read to it, write to it 143
etc. 144
So now once I hit enter it will ask me for my password again which I'll just type in. 145
And now we should be good to go. 146
Now before we test it, the first thing to do is to simply quit the terminal. And we're going to open up 147
a new fresh instance. 148
And here we're going to type mongo --version and when we hit enter 149
if you get something that looks like this where it tells you MongoDB shell version is 4.0.3 150
then that means that everything is all set up and you are ready to go and proceed to the next step where 151
I will learn all about MongoDB. 152
Now if at this stage you get something like bash mongo not found then it means that there might have 153
been something that would have gone wrong in the steps that led to this point. 154
So it might be worth just reviewing the steps again in the blog post and just go ahead and step by step 155
confirm that everything's been done to the exact spelling and exact casing and just make sure that you 156
haven't missed out any steps as well. 157
But if you've gotten to this stage then 158
well-done congratulations. You've finally managed to install MongoDB on your local system and you are 159
ready to proceed to the next step.