In this video you're going to install Mongo D.B. on your machine that's going to allow you to actually
start up the Mongo DB server and connect to it from node j s.
Now this video is for Mac and Linux users only if you're on Windows.
I've created a separate installation video for you.
That's the next one so you can stop watching now and jump over to the next video if you're on Windows.
If you're still watching this one I'm gonna assume you're running on either mac or linux and we're gonna
work through the installation process.
You can grab mango D.B. by heading over to get mango D.B. now from here.
There are a lot of different things we can download.
We have cloud options server and tools.
We want to grab a server that we can actually run on our machine and there are two options here.
The community server or the enterprise server we're gonna be using the community server which is the
free version of Mongo D.B..
We'll be able to get up and running on our machines down below before we can download.
There are three things we can pick version OS and package now right here.
You want to pick the current release even if that's greater than what you're seeing for me.
So the current release right now is four point zero point four.
If you're seeing a more current release you want to grab that as I'll be updating the videos to account
for any changes.
Next up is the OS.
So for Mac users you want to stick with Mac OS and do you want to grab the T GC archive of all of the
Mongo D.B. files.
If you're running on Linux you want to change the OS.
You can see a bunch of different distributions listed here.
So as an example if you were running on the latest a boon to eighteen point zero or you could grab that
here then you can pick your package.
Now for Mac the only option you had was the GC archive for a boon to an other Linux distributions.
You're gonna have other options.
You want to switch that over to teh GC to get everything working correctly.
So if you're on Linux.
This is what you want.
I'm going to switch over to Mac to actually grab the archive for myself.
I don't have Mongo DB installed.
We're going to work through the process together as it's a more manual setup then something like no
JSA where we have a nice wizard the installer walks us through all the steps with Mongo D.B..
There's a little manual work that needs to be done to get everything up and running once the download
is complete.
You want to go ahead and crack open the finder on Mac or your file explorer on Linux and navigate over
to the downloads directory.
Here we have our archive and I can double click that to extract its contents.
What's inside of there is what we need it to actually manage our Mongo DB server.
So in here we have they been directory the bin directory contains a bunch of executable is which we
can use to perform various tasks.
The main one is Mongo DB which we can use to start up the Mongo database server.
So before we actually run this executable we want to take this directory and move it to a more permanent
place on our machines.
I don't know about you but for me the downloads folder is basically a temporary directory that gets
deleted every few days or so.
So we want to move this to a place where it can live long term.
Before I move it I'm going to update the name of this directory.
Right now it contains a lot of additional unnecessary information.
All I'm going to do is rename this folder from what it currently is just over to something simple like
Bongo D B.
Now from here what we want to do is put this somewhere permanent and a great place to put it is the
user folder on your machine.
I'm gonna crack open another finder window.
I'll navigate over to the user directory and from here I'm going to take that Mongo DB folder move it
out of the downloads directory and move it into its more permanent location.
Now once it's over here we're almost ready to start up the server.
The next thing we need to do is create a place for our data to be stored.
Now by default Mongo D.B. expects you to create a data directory at the root of your hard drive and
in there it expects a D.B. directory.
That's not ideal for many users as you're going to run into a ton of different permissions errors.
It's much better to create a directory inside of your user folder to store the data.
So right here I'm going to create a new directory in the same folder where I have Mongo D.B. and I'll
call this Mongo D.B. hyphen data.
So I have Mongo D.B. which contains the executable is necessary to actually start things up and manage
our database and they have Mongo D.B. hyphen data which is currently empty but which will shortly start
to contain our databases data.
Now that we have both of these in place we're ready to actually start up the database and we do that
by running a single command from the terminal.
For me I'm going to navigate back over to visual studio code and from the terminal we are going to run
one of the executable is in that bin directory.
Now if you put the directory somewhere else on your machine your command is going to look a bit different.
To start we need to get the path to our user directory.
Now if you already know that you can simply type it out.
If you don't know it you can run C.D. space tilled up to navigate to your user folder and from there
you can use it p WD to print the current working directory when you run that command.
It's going to spit out a path.
And this is something we're going to use in the command to start up Mongo D.B. so to kick things off
we have to list out the path to the executable.
So for me it is forward slash users forward slash Andrew which is exactly what I got right here.
Then forward slash Mongo D.B. which is the name I picked for my directory.
Forward slash bean forward slash Mongo D.
Then we use the D.B. path argument to provide a path to that data folder we created.
So that would be once again forward slash users forward slash Andrew.
Then forward slash Mongo D.B. hyphen data.
So this is the complete command for me.
Make sure to just swap out the beginning portion with whatever you got from TWD when you were running
that command from your user folder.
Now when I kick this off we're gonna get a ton of output as it initialize is the database and gets the
database up and running.
Right here I'll hit enter to run the command.
We have all sorts of output as it starts itself up and we can see that after all of that happens it's
just sitting and waiting.
The server is up and running and now it's waiting for connections to the database where the connector
can read and write from the database adding documents querying documents updating documents or deleting
them.
Now if we go back over to the finder we can see the Mongo DB data directory now has a ton of information
inside of there.
This is all just to initialize things.
There are no actual documents as we haven't created any just yet but we now do indeed have the server
downloaded on our machine and we know the command we can use to get the server up and running.
One thing worth pointing out from the output comes maybe 8 or so lines before the end.
Right here we have the following message waiting for connections on Pt. 2 7 0 1 7.
This is letting you know that your Mongo DB database is up and running.
And this is just the default port that Mongo D.B. uses.
Now that the database is up and running you can connect to it from node J.S. to start reading and writing
data.
Now the next video is the Mongo DB installation video for Windows users so you can skip that and move
on to the following video which is the video where you'll actually connect from node.
I'm excited to get to it.
So stay tuned and I'll see you soon.