- [Instructor] Authentication is very often performed
against a user database, and we will use MongoDB for that.
And setting up MongoDB can be a bit complicated
depending on your operating system,
we will use Docker to run it.
Make sure that your Docker daemon is running.
Here, I'm going to make you see this Docker icon
on my task bar, when I click it I see
that the Docker desktop is running,
and then I head into the terminal
and there I now run docker pull mongo.
This will pull down the MongoDB image
directly from Docker Hub.
Now we have the MongoDB image on our machine
and, of course, we now have to run this Docker image.
And for that, I now run docker run --name,
and we will call this running container mongodb,
and then I do a port configuration,
and there I add -p 37017:27017.
What this does is it maps the default MongoDB port,
which is 27017 in the Docker container,
to my localhost port, so the 7017,
and I can use that port then to connect to Mongo DB.
And then I also have to add -d, for run it as a daemon,
and then I also have to, of course,
tell which image this is, and if I now hit return
I have a running image.
I can verify that by typing docker ps,
and there you see, here,
we have this running Docker image now.
It might happen that this container stops,
or you just restart your system and Docker
is then not running anymore.
To restart this container again, you can always later run
docker start mongodb,
now, of course, MongoDB is already running.
When working with databases it's always a good idea
to have some graphical interface to it
so that you can look at the content in the database,
and we will install one for MongoDB now.
I chose to use MongoDB Compass, it's free
and provided by the company behind MongoDB.
Just look up MongoDB Compass,
and you should end up on this page and you can, there,
download MongoDB Compass for free.
I already did that, so now when I run MongoDB Compass
it first will start up, this takes a little bit,
and then I want to connect to MongoDB running on Docker,
and for that I select, here,
Fit in connection fields individually,
and I want to connect to localhost
and there I use 37017 as explained before,
this is the port that is mapped to the internal port
of the Docker container.
And for authentication we can leave it to none,
and I can now, simply, click Connect.
If everything went well, you will be presented with a screen
similar to what you see here.
So this shows, already, some system tables of main MongoDB,
some system collections and, of course,
when we then add our authentication databases
they will show up here as well.
Now MongoDB is running on your system
and that was actually quite easy.
Of course, for production deployment, setting up MongoDB
is way more challenging.
There are a lot of configuration options
like security storage engines, replications,
and you might even want to consider tweaking
your file system in kernel settings to make MongoDB
run smoothly under high load.
For a sample project, though, this setup will fully suffice,
and we will look at them in the next video.