-: In the last section, we got MongoDB up and running.
Just to make sure we're on the same page here
in my terminal, I've got MongoDB very clearly running
by executing the command MongoD.
So at this point in time
we wanna make sure that Mongo is running in a separate tab.
I'm gonna flip back over
to the tab that's hosting Node Mon right now
and then I'm just gonna go back to my code editor.
So at this point in time
we've set up Mongoose with the one single model.
We've got Mongoose running, we've got MongoDB running.
There's just maybe one last missing tiny piece in here.
So we have Mongo- Mongoose running on our server,
but we actually have not formed a distinct connection
between Mongoose and the MongoDB server
that we're running host locally.
So by default, Mongoose does not try to reach
out to your local host and connect
to just any old MongoDB server that's sitting there.
We have to specifically tell it, hey, Mongoose
please go connect to this instance of MongoDB.
To do so, we need to write some setup code
inside of our index.js file.
So inside index.js, I'm going to require Mongoose.
And I'm gonna make another new section
in here called DB setup.
And this is where we're going to tell Mongoose,
hey go connect to this very particular instance of MongoDB.
I'm gonna say Mongoose.connect and then we're gonna
essentially pass it a URL of sorts here.
We're gonna say MongoDB colon slash slash local host.
That means on this server, and then colon auth slash auth.
Internally, this creates a new database inside
of MongoDB called auth.
So if you want to call your database something
slightly different, this would be where you'd change it.
Just right here.
I'm gonna save this file
and now I'm going to Node mon just reran.
So Node mon just node mon just restarted.
I'm gonna flip back over to my Mongo process now
and you can see that I've had several connection accepted
from blah, blah, blah.
Let's go ahead and see what happens
if I kill the Node mon instance that's running.
So I'm gonna flip back over to Node mon
and I'm gonna hit Control C just to stop.
Then I'm gonna go back over to Mongo, and sure enough
I get end connection from 12701.
So that is the server that we were just running.
So we had made a connection with Mongoose
and by ending it, we close the connection.
I'm now gonna go back over to the server.
I'm gonna run NPM run Dev again.
Server starts up, I'm gonna go back over
to MongoDB and connection accepted from 12701.
Perfect. So that means that our server, you know
we've got reasonable belief at this point that
our server is making connection with our MongoDB instance.
So this is fantastic.
There is one more little interesting thing that I
wanna show you guys about MongoDB
that we're going to make a lot
of use of in the coming sections.
Right now when we run MongoDB
it's just running the command line, right?
We can't really see any, any
of the data in here or anything like that.
It would be really fantastic for debugging though
if we could kind of reach directly
into the database and see what records we have.
So there's a fantastic tool that we can download
to do this for us.
It's called Robo Mongo.
So in my browser, I'm going to search for Robo Mongo.
And then the first result on here
I'm gonna find robomongo.org.
I'm gonna go this page at the top right, I'll find download.
And now by default, Robo Mongo is going to ask you
to download the latest version right here at the top.
And if you wanna download the latest version
you have to buy it to download it.
But if you don't wanna spend money
and I don't blame you, if you don't, no problem.
You can download older versions of it.
And basically we're talking about just the, you know
most recent version for free.
So only the latest version you have to pay for,
previous versions you can get for free.
So I'm going to download this
and whatever platform you're on, just go ahead
and download and then go ahead and install it.
So at this point, I encourage you to pause the video
and go through the installation process.
Once you've got Robo Mongo working
let's go ahead and start it up.
So I'll run, oops, Robo Mongo to start it.
I've already got an instance running.
Sorry about that. Let's restart. There we go.
So by default, when you first open Robo Mongo
you won't have any connections listed in here
so I'm just gonna remove my connection just
so we look the same. Very good.
Now, the connections that these are references
to a connection is a connection
to an actual MongoDB database.
So I'm going to create a new connection.
The default settings in here are fantastic,
so we don't really have to change these default settings.
I will change the name, however,
I'm just gonna change the name
to local host just to make it clear that, hey
I'm running this on the local host right now.
I'm gonna save this and makes a new record
and then I'll connect to it.
On the left hand side, I've got a database called auth.
I'll expand on that, and then I expand collections.
And you can see I've already got a little bit
of data loaded in here.
That's totally fine.
Chances are you just have an auth
or maybe not even auth at all.
So as long as you can see essentially local hosts
and system over here, you should be good to go.
Now that we've got Robo Mongo set up
let's go onto the next section, create some new data
inside of our database, and then we can verify it inside
of Robo Mongo and just see it in action.
So I'll see you in the next section.