So enough of the theory for now,
let's install MongoDB and
all the tools we need for spinning up databases,
for interacting with databases,
and the best place to start with that is Mongodb.com.
Now on this page, you got various offerings,
you've got cloud services and you've got software.
Now, cloud services are in the end, managed MongoDB
servers running on some cloud machines.
So hosted by MongoDB company
And we'll take a look at some of these parts
later in the course
for the moment, let's focus on software,
which is software, We install locally on our system.
Now in this lecture,
I'll start with macOS, in the next lecture,
I'll show you how to install and start MongoDB,
and the MongoDB server on Windows.
For Linux, I unfortunately don't have a Linux machine.
So therefore,
I have to point you at the official docs and therefore,
you should actually stick around
for a couple of extra seconds here
even if you are not using Mac,
because I want to dive into those docs together with you
first before we then do continue
with the macOS setup in this lecture here.
But first of all, let's take a closer look at the software
where we can install.
Most importantly,
we've got a community server and an enterprise server.
Now the community server is a free version of MongoDB
of all you need for working with MongoDB
And that's the version we're going to use in this course.
The enterprise server adds more additional enterprise level
features, but this does not affect how MongoDB works
or which command you can execute.
Instead here,
we're talking about additional configuration or security
features that might matter to you
if you are a big enterprise.
But for developing with MongoDB,
the community server is all we need
and when it comes to deploying MongoDB,
we'll take a look at these cloud offerings again, later.
Now, we also got more tools.
Most importantly Compass is also noteworthy.
It's a graphical user interface that allows you to interact
with your database and to view the data in your database.
It's a little bit like MySQL workbench for MySQL,
if you've worked with that, but we'll ignore it for now.
Instead, we'll install the community server
and for this we can click on it
and we should be taken to a page that looks
something like that.
Here you can select the version and I'll use the latest
stable one.
And then your operating system, actually,
your operating system should already be preselected,
but you can select from a wide range
of operating systems here
including windows and a bunch of Linux distributions to make
sure you're downloading MongoDB for the correct system.
And then you can click this download link here to start the
download and download MongoDB or these core tools that you
need onto your system.
Now we'll take a look at what we downloaded there in a
second, but for the moment, let's go to the docs here,
the documentation,
and here we want to go to the server documentation,
which actually is a great resource
to look up MongoDB features in general,
and we're going to go through
all these key features throughout
this course, for the moment,
Let's dive into the installation documentation,
and here we want to view the docs for installing the
community edition.
And now you can choose the guides for your operating system.
And it's a great idea to go through these written guides.
In addition to this video,
especially if you should get stuck, or if you are on Linux.
Now, if we install it on macOS
we've got different ways of
installing MongoDB,
we could also install it with Homebrew,
which is a command line tool. You can run on your system,
but we did actually download this Tarball.
So we're going to go through these installation steps here
and now in there, we, first of all,
have to download this Tarball.
There's a zipped folder in the end,
which we did a couple of seconds ago.
Then we have to unzip it,
which you can do as instructed here,
but even easier than that,
you can also just locate that downloaded TGZ file,
which in the end just unzipped file and double click on
it in finder
here, I moved it into some software folder,
which I created somewhere in my user folder on MacOS
but you can move and extract it anywhere you want.
Then I'll delete the zip file. And then here,
I got a folder with a couple of files in it,
especially with a bin folder inside of it,
where we then got a variety of executable files in the end.
And for us,
the most important files will be the MongoD
and the Mongo file.
Mongo D will be an executable file that actually allows us
to start the MongoDB database server,
which is the server that hosts the databases and which needs
to be up and running for us to interact with them and with
the data in them.
And the Mongo executable actually will be a shell,
which we can use to talk to that server.
So that will be the tool we use for running queries against
the database server.
Now, as I mentioned before,
there's also a graphical user interface.
You could use MongoDB Compass, but actually
for this course,
we're going to stay in the shell because it is about
learning these commands and query commands
and while executing them through the shell is the most
straightforward way of doing so.
A graphical user interface can be a nice tool to help,
but it will not be our main way of interacting
with MongoDB.
Now, of course, with MySQL, we did actually use the,
MySQL workbench a lot,
but there keep in mind that we had to do things like
configuring our database and the table structures in there
with MongoDB and no SQL databases in general
that's not a main task we have to do because there is no
database or a table structure.
Instead, it's only about running these commands
and if you recall the MySQL section there,
we also ran commands,
sequel statements with help of MySQL workbench
But in the end we just executed commands there
we type commands and executed them.
And we're going to do the same thing here
with this Mongo shell,
just without the overhead of this graphical user interface,
which has a lot of options, which we don't need.
So that's why,
these will be the two important things for us
in this course section here
but how do we now execute these files?
You could double click on them,
but that's not really how we want to do that
instead, we want to invoke them
through the terminal here on macOS
and to do this efficiently
we want to make them available as global commands on our
system.
And the official documentation tells us how we can do that
effectively, we got these two approaches here,
which we can use.
We can copy the files into this user local bin folder here,
or we create so-called symbolic links.
Now this might sound a bit more advanced than these commands
might look a bit more advanced, but in the end,
what we're doing with that is we're turning these executable
files into commands.
We can run from inside the terminal on our system,
just as we could run the node command from inside the
terminal on our system.
Now to make that all work on macOS, it's easiest
if you right click onto the bin folder
and you then open a new terminal
at that folder,
alternatively,
you open your terminal just like that.
And you then #cd you navigate into that path where these
files are located. So into the bin folder here, ultimately,
but it's,
if you just do right click here and opened a terminal
already navigated into the path by clicking this option
And then what you want to do is
you want to run this command here
from the official docs
So copy that command, paste it in there,
but don't execute it yet.
Instead, since we're already in that bin folder,
we want to shrink this first part here to just copy
. / *
which copies the content of the current folder into this
folder, which you want to keep,
then hit enter,
and you might be prompted for your password here.
And once you entered your password correctly,
which I didn't manage to do on the first two tries,
as you can see,
this should be done
now to verify that this not all worked
simply type Mongo into your terminal,
and this might give you a warning like this,
so that it's not allowed to start.
If that happens,
go to your system preferences and there to security and
privacy, and then there,
and click on allow any way
due to same for all the other MongoDB commands
you might execute throughout this course
Whenever you get this warning you just saw.
once you did that, if you try running Mongo again,
this time to get a different warning,
we can click open there,
and now it executes it still crashes because actually it
fails to connect to a MongoDB server,
but it at least did recognize this command now.
And that's the important thing here.
Now what's missing at this point though,
is the database server itself.
We need to start that before we can actually successfully
run Mongo, the Mongo shell,
and connect to it and work with it.
Now in a database server would be started by running the
Mongo D command,
But before we run this,
we have to prepare our system a little bit, to be precise
we have to prepare POV folders on our system
where MongoDB will be able to store
the actual database data and some log files,
because when working with a database like MongoDB,
but the same is true for all databases. Of course,
eventually the data will be written to your hard drive and
you need to tell MongoDB where data should be written to.
Therefore what you want to do is you want to create some POV
on your system where that data should be stored.
And for this here, I got a development folder,
which is directly in my user folder,
where I will create a MongoDB folder.
And in there I'll add a data folder
and I'll add a logs folder.
Now you can add such a structure anywhere on your system.
Just make sure that it's somewhere in your user folder in
the end, so that you have full read and right access to it.
So don't create it in some reserved system path or anything
like that.
Instead, your user folder is a good starting point
And then some sub folder there is a good starting point
In my case,
it does development folder where I have the MongoDB folder
where I have these folders I just created.
So usually create a structure that looks something like this
folder wise.
Now, once you have these empty data and logs folders,
you can actually now start Mongo D.
Now, first of all, we can run Mongo D just like this,
because it will fail anyways,
because MacOS will block it.
So to work around that, again,
we go to the system preferences and allowed us anyways,
and now we could run it successfully.
But before we now run it again,
we want to configure it a little bit.
So we'll type Mongo D and then a blank.
And now we want to make MongoDB
aware of the data and logs POV we just created
And for this, you add a so-called flag,
a so-called option to this command to configure this
command.
You do this by typing dash dash and then DB path is the
option name we want to add here.
And with that, we can tell MongoDB
where the data should be stored
So that's a special option MongoDB
would be watching for
then you add a blank and then the path where the data should
be stored, and to get that path,
you can go to that data path, you created
and right click on it and choose
get info here on macOS
and then you can copy this path here
in the where part and paste it in here,
and now just make sure that it ends with slash data or
whichever name you chose for your data folder.
So that is the first important part
with that will tell MongoDB
where to store the data
And you want to add this option whenever you restart your
Mongo DB server.
For example,
if you was shuts down your operating system and you
restarted it,
and you now want to restart your Mongo DB server to work
with it again, you have to restart it like this again,
but we're still not done. Add another blank.
And here for me,
it's doing it in a new line because I ran out of space here,
but it's technically still the same command in the same
line.
It just added this line break for readability reasons don't
hit enter, because that would confirm to command
And you don't want to do that yet instead,
just add a blank and then also add another option
with dash dash and that's the Logpath option.
And here, we now want to get the path to our logs folder,
which of course is the same path just ending with slash
logs in my case
to point at this logs folder
Now, for the logs,
you then also actually have to point at a concrete file that
should be created.
So add another slash and then Mongo.log
like that The name is up to you,
but Mongo.log is a common name for that log file
for the data path you did not specify such a file
Now you can hit enter,
and you might see another warning where you have to
confirm that you want to open this command, this tool,
but with that,
eventually it should now start this Mongo DB server
successfully.
And you can tell that it's successful by the fact that it
does not crash.
And that you now start at such an ongoing process.
You're not back to the regular input mode anymore. Instead,
this is a running process,
which you can always quit with Control + C
so by pressing
control + C
But if you do quit,
you won't be able to interact with the database anymore.
You have to restart it then to do that again.
So as long as you are working with dad, Mongo DB database,
you want to keep that process up and running.
So you don't want to close that terminal window and you
don't want to hit control + C here instead
Now we can open a new terminal window, for example,
by pressing command + N here on macOS
So I still have the other process running here,
and now I have my new window here,
And in here,
we can now try to connect to this running server.
And we do this by running this Mongo command,
which I showed you before,
which under the hood uses this Mongo shell.
If you hit enter like this,
it should automatically connect to your server.
It gives a bunch of log information output here,
but eventually it will connect.
And now that you are connected,
you can interact with that server.
For example, in here,
you can run show DBS to see all the databases that are
running on your database server,
and you'll have some default databases out of the box here.
Now that's the point where we'll stop here.
We'll pick up on this in the next lectures again,
if you're facing any problems here,
definitely have a look at these official docs for MacOS
to go through the installation
Step-by-step again,
with help of that written guide and eventually have that
running server and connected shell on your system as well.
Now let's continue with windows.