WEBVTT

00:00.330 --> 00:04.620
So now we have the connection string for the MongoDB.

00:05.860 --> 00:09.460
Database, the cloud, MongoDB instance.

00:09.460 --> 00:13.420
And now we need some way to connect to the MongoDB database.

00:13.660 --> 00:19.210
And something we can use is what we already imported up here, which is called Mongoose.

00:19.210 --> 00:27.280
So Mongoose is sort of a JavaScript MongoDB driver, which means it contains a lot of functions that

00:27.280 --> 00:37.480
you can use to use MongoDB functions such as getting a list of objects or documents and saving models

00:37.480 --> 00:41.920
and so on, and connecting, of course, rather than doing.

00:42.730 --> 00:46.390
Ready raw commands inside of MongoDB.

00:46.450 --> 00:50.000
You have this nice interface to use it.

00:50.020 --> 00:57.340
Anyway, let's try and connect it and get connected to the MongoDB instance we have.

00:57.700 --> 01:03.670
So we go in, I go async function and I write connect to.

01:04.530 --> 01:06.240
M-lab or MongoDB.

01:08.170 --> 01:09.820
And in.

01:09.820 --> 01:10.750
Here we go.

01:10.780 --> 01:14.170
Await Mongoose Connect.

01:15.030 --> 01:16.920
And then we just copy in.

01:18.090 --> 01:19.740
This string over here.

01:21.250 --> 01:30.610
And also you need to use a little option here which says use new URL parser, set it to true.

01:31.030 --> 01:35.680
And if you don't set it to true, you're going to get a warning about that.

01:35.680 --> 01:43.330
The old URL parser is being deprecated, so you need to pass in this option here and.

01:43.780 --> 01:45.220
Okay, so.

01:46.290 --> 01:50.490
Once that is done, I will make a new async function.

01:51.240 --> 01:52.680
Call it main.

01:54.340 --> 01:56.620
And we'll call.

01:58.320 --> 01:59.940
Connect to.

02:01.990 --> 02:02.860
MongoDB.

02:04.030 --> 02:08.650
And then once that is done, we will call this function, which I will call.

02:08.650 --> 02:11.010
I will rename it to Reddit.

02:11.590 --> 02:12.880
Scrape Reddit.

02:14.660 --> 02:15.800
And.

02:19.910 --> 02:20.960
There we go.

02:21.560 --> 02:25.580
And then we call Main down here, as we did before.

02:25.580 --> 02:27.080
And now.

02:28.340 --> 02:32.060
Let's put a console log underneath the connect here.

02:32.060 --> 02:36.530
So we say connect it to M-lab.

02:38.940 --> 02:42.540
And yeah, let's try and run it.

02:42.540 --> 02:49.140
So I'm just going to comment out the scrape Reddit so we can just see if we actually connect to the

02:49.560 --> 02:50.550
database.

02:51.500 --> 03:00.530
So node index.js and we see the connected to lab string or console log here and that means we could

03:00.530 --> 03:05.420
go further on and get into actually saving models to MongoDB.

03:05.450 --> 03:06.080
Now.
