Narrator: Welcome back.
In this lecture, we will install MongoDB on macOS.
Now, if you're a Windows user,
then please mark this video as completed,
and move on right to the next one
because the installation process
is actually quite different on Windows
than it is on Mac.
So fire up your browser,
and open MongoDB.com.
Okay?
Then, move to products.
And then over here, the MongoDB server.
So, open that one up.
And so that takes us to the MongoDB download center.
So the one that we want is the MongoDB community server,
and then of course, the current release.
So not the more experimental four point one.
Then, your OS should automatically
be selected as macOS.
And then the package.
This is the only option anyway.
And so, hit download.
And then wait for it to complete.
Now while this is downloading,
notice how the website here talks about MongoDB Atlas
which is Mongo's database as a service.
So basically, it's running MongoDB in the Cloud on Atlas
instead of running it locally.
And actually, later in this section,
that is exactly what we're gonna do.
So we will create an Atlas account,
and run our database in the Cloud.
Okay?
So in this video, we're downloading and installing
the local version of MongoDB,
which we will use to get familiar with the database system.
But then, by the end of the section,
we will actually transition to the hosted version,
and that's the one we will then use
in our real application until the end of the course.
All right.
And with the file now downloaded,
let's go ahead and extract it,
and take a look at the content.
And what we need here is basically
these executable files here.
And what we need to do with them
is to copy them into a special binary folder
that we have on our system.
Okay?
So let's move into our terminal and do a copy command,
and we're gonna need some permissions forwarded,
so I'm starting with sudo here.
Then cp for copy.
And now, I'm gonna go add and drag
all of these files in here so that
I don't have to write the path to them out.
Okay.
So that's all of the files that we're gonna copy.
And we will copy them into a folder
called slash usr local slash bin.
Hit return on that, and just to make sure
they're actually there, let's actually go there.
Usr local slash bin.
Take a look at the files there.
And indeed, here they are.
So basically these red files are the ones
that we just copied there.
So these aren't executable.
Now since we're in this folder,
you might actually see some other interesting stuff here.
For example, there's nodemon command here.
That is the global nodemon package
that we actually installed before.
I mean, it's not really the package itself,
but it is this what allows us to run
the nodemon command globally.
Next up, we're gonna create a folder
where the database can then actually store the data.
And again, we're gonna need permissions for that.
So mkdir to make the new directory,
and then slash data slash db.
Hit return.
And in my case, this folder actually already exists.
And so, I'm not able to create a new one.
But in your case, I'm sure this worked just fine.
Next up, we need to give some permissions
in order for the database to be able
to write in this folder.
And so for that, again, we use sudo.
Then this weird command here, chown, or whatever.
And R for recursive.
Then id minus un and slash data slash db.
All right.
So this looks a bit like black magic here,
but again, just follow this recipe
in order to just make this work.
Anyway, we should now be good to go.
And call mongod.
So let's try that out.
So let's make this window a bit bigger.
And so indeed, we now have the Mongo process running here.
Okay.
So it starts up here.
And then gives us all the stuff that we don't really need.
And by the end, it tells us that it's waiting
for connections on port 27017.
Okay?
So this here is basically like a Mongo server.
Okay?
So this means that MongoDB is now running in the background.
But we need to now actually connect to it
in order to create new databases,
and create new collections and all that good stuff.
Okay?
So in this terminal window,
we will leave this process running.
So basically this MongoDB server.
And we then open another tab,
or you could open another window.
But I just use command t to open another tab.
And now, we run the Mongo shell
simply by writing Mongo.
All right.
And we are now connected to our MongoDB server
that is running on local host on the default port
that I just mentioned before.
So this one.
Okay.
So we are now connected to that,
and so let's now write db here,
which should return the task database.
And it did.
So.
We have a test database already on our computer.
And so this means that it works.
So, great.
Now we could have used this Mongo shell here
to also connect to a remote database.
So, remember how in the beginning,
I talked about the MongoDB Atlas
which is basically a database running in the Cloud.
So a remote database.
And so here, we could use this MongoDB shell
to also connect to that one.
But if we simply run the mongo command like we did here,
it will just automatically connect
to the local MongoDB database
that is running on local host.
Okay.
So that's it for this video.
In the next one, we will then create
our first new database, and start
to interact a little bit more with this Mongo shell.