Instructor: In the last section,
we created our User Schema,
we created a model out of it
and then we exported that model.
Keep in mind that this is all working
with Mongoose right now, and we haven't touched anything
or even installed MongoDB,
which means we don't really have any database yet whatsoever
even though we've got our Schema right here.
So let's spend some time in this section
to actually wire up MongoDB and get it installed.
Installing MongoDB is largely platform specific,
so I am running OSX.
Of course, if you're running Windows or Linux,
the installation is gonna be just a little bit different,
but let's walk through the process a little bit
and I'll tell you where you should be branching off.
I'm gonna open up my browser
to pull up some installation directions.
In a new tab, I'll just search for MongoDB,
the first result is gonna be mongodb.org, go there,
and at the top of the page, find the DOCs section
and then we're almost there, on the left-hand side,
find Installation, so we'll go to Installation
and then we'll scroll down just a little bit,
little bit more, a little bit more,
a little bit more until we find Tutorials.
So these are nice walkthroughs on how to install MongoDB
given a specific platform.
So at this point in time, if you're running Linux
or you're running Windows,
feel free to follow these other sets of instructions
and catch me in the next section, okay?
So basically pause the video, now do installation
and then just go to the next section.
If you have any difficulty with installation
I highly recommend first, if you're getting an error message
just go ahead and do a little bit of googling
on the error message.
If you still can't solve it, feel free to drop me an email
and we'll try to work through it.
So at this point in time, I'm gonna continue forward
with the directions for installing on OSX.
So I'm gonna click on this link,
we'll scroll down a little bit,
scroll down, scroll down, scroll down
and here we go.
So we have step number one,
which is to update Homebrew's Package database.
So Homebrew is a package manager that gets included
with OSX by default.
Over in my command line, I've already ran brew update,
so I'm not...
It takes a little bit to get through,
so I just did it ahead of time,
but I highly recommend you run brew update at this time.
Once brew update has ran successfully,
we'll go onto the next step, which is brew install mongodb.
So I'll do brew install mongodb.
Now I've already downloaded the package ahead of time,
so it almost instantly installs.
Next, we need to do a little bit of setup from MongoDB.
I'm gonna keep scrolling down,
we're gonna pass the Install Community Edition Manually.
Keep going, keep going,
keep going, keep going until you find, Run MongoDB.
So the first thing we need to do here,
is create the data directory.
So by default, Mongo needs a place to actually save the data
that it collects
and by default it does so in this data/db directory.
So this directory does not exist by default
and Mongo will not create it for us,
so we need to actually create it.
Inside of my command line,
we will do just like the line says,
mkdir-p-data or /data/db.
And if you get an error there, no problem,
you might have gotten something that says like,
permission denied, blah, blah, blah.
You can just run sudo mkdir-p /data/db like so.
Once that's done, we need to actually go ahead
and set some permissions on this directory.
So unfortunately this part
is where it gets a little bit messy.
(chuckles)
So this directory that we just created
requires special permissions to access.
And so if we go over here,
I don't think this page actually has the directions
that's fine.
To take over control of that directory,
basically, we need to take over ownership of the directory
we just created.
So here's what we're going to do.
We're gonna do a little bit of fancy command line work.
Well, it's not that fancy, but let's just give it a shot.
So I'm gonna write sudo we'll change ownership-R
$USER/data/db, like so.
So basically what this command right here does,
is it just takes ownership of the directory we just created.
I get prompted for my password, no problem,
and boom, there we go.
So now the very last step is to actually start MongoDB up.
To start up MongoDB, we just run Mongod, no b here, just d,
and there we go.
So you should see some messages on here like up at the top,
MongoDB starting, we should see initializing full-time,
blah, blah, blah
and then waiting for connections on port so and so.
One thing to keep in mind is that by default,
if you wanna use Mongo you have to run that Mongo D command.
So let's say I go and restart my laptop now,
this process and this window would end,
which means Mongo would no longer be running.
So every time they wanna make use of Mongo,
I need to run that mongod command.
If you don't like that,
if you want Mongo to just always run in the background
by default, when we did the Homebrew Install,
there was actually some directions right here
on how to get MongoDB started at login.
So again, I like running it myself,
it's totally up to you if you wanna run it at login.
I really like logging it myself
because I can see any error messages that pop up
or anything like that.
I can also see connections
as they're created to the MongoDB instance.
Okay, so this is great, we've got our server running,
let's go ahead and continue in the next section.
I'll see you there.