- [Instructor] To get started with MongoDB,
we first have to use Docker to download
and run a container for it.
Make sure that your Docker daemon is running.
Here on my system, I can just click on this Docker icon
in my taskbar and see that the desktop daemon's running.
And then I will start in my terminal
that I opened already by running docker pull mongo.
This'll pull down the latest MongoDB image from Docker hub.
Next, we have to start this container,
and for that, I will now run docker run --name,
that's the name of this container,
and I will call it mongodb.
And now I'm adding -p
and then I add some port configuration.
So I will explain this in a second.
I now add 37017:27017.
This tells Docker that it should map
the internal default port of Mongo DB
of 27017 to 37017.
I'm doing that this way just to make sure
that if you have Mongo DB already running on this system,
that this does not collide.
And then in the end, I add -d.
This tells this container to run in the background.
And in the end I also have to, of course,
tell which image Docker should use,
and this is Mongo,
that's what we just pulled down.
So let's execute that,
and we get some hash as returns,
so this looks good.
If you get this hash,
this means the operation worked.
And to see our container, I can now run docker ps.
And you see that we now
have a container called mongo running.
It might happen that this container is stopped
while you go through this course.
Maybe you restarted your computer
or something went wrong, who knows?
In this case, you can just run
docker run mongodb
to run this container again.
Let's just try this out.
So I can say docker stop mongodb,
this will stop the container.
And then if I run docker ps,
I see that there is no container running,
and to run again, I can just say docker start mongodb,
and I will be back at the running container.
When working with databases,
it's always a good idea
to have some graphical user interface to it,
and for that, we will install one for MongoDB now.
I chose to use MongoDB Compass.
It's free and it's provided by the company behind MongoDB.
So let's head into the browser.
And I already have this page open.
Just look for MongoDB Compass in your search engine
and you will basically end up on this page.
And there, you can simply download
and install it for your operating system.
You see that it's available for Windows,
but also Linux and MacOS.
I already did this,
so I will just type compass in my search box
and this will bring me to MongoDB Compass,
and let's run it.
And it presents you with a page
to connect to a MongoDB server.
And I will first select to fill in
the connection fields individually.
And we are on local host,
so I can leave that to the default,
but for the port, I will now enter 37017,
then I click on CONNECT.
And once it's connected,
you'll see the databases
that are currently in this MongoDB server,
and these are admin, config and local.
These are system collections
that come with every MongoDB install.
And right now there is nothing much to see,
other than the startup log.
Now we have a running MongoDB server on your system,
and as you see, that was not really hard.
Of course, from production deployment,
setting up MongoDB is way more challenging.
There are a lot of configuration options,
like security, storage engines and also replication.
And you might even want to consider
tweaking a file system and kernel settings
to make Mongo DB run smoothly under high load.
For a sample project though,
this setup will fully suffice.