So now we have the connection string for the MongoDB.
Database, the cloud, MongoDB instance.
And now we need some way to connect to the MongoDB database.
And something we can use is what we already imported up here, which is called Mongoose.
So Mongoose is sort of a JavaScript MongoDB driver, which means it contains a lot of functions that
you can use to use MongoDB functions such as getting a list of objects or documents and saving models
and so on, and connecting, of course, rather than doing.
Ready raw commands inside of MongoDB.
You have this nice interface to use it.
Anyway, let's try and connect it and get connected to the MongoDB instance we have.
So we go in, I go async function and I write connect to.
M-lab or MongoDB.
And in.
Here we go.
Await Mongoose Connect.
And then we just copy in.
This string over here.
And also you need to use a little option here which says use new URL parser, set it to true.
And if you don't set it to true, you're going to get a warning about that.
The old URL parser is being deprecated, so you need to pass in this option here and.
Okay, so.
Once that is done, I will make a new async function.
Call it main.
And we'll call.
Connect to.
MongoDB.
And then once that is done, we will call this function, which I will call.
I will rename it to Reddit.
Scrape Reddit.
And.
There we go.
And then we call Main down here, as we did before.
And now.
Let's put a console log underneath the connect here.
So we say connect it to M-lab.
And yeah, let's try and run it.
So I'm just going to comment out the scrape Reddit so we can just see if we actually connect to the
database.
So node index.js and we see the connected to lab string or console log here and that means we could
go further on and get into actually saving models to MongoDB.
Now.