WEBVTT

00:01.350 --> 00:05.940
Now it's time for us to write out this schema for our mongoose model.

00:05.940 --> 00:14.490
So Mongoose is special compared to the raw MongoDB driver in the sense that you define a schema for

00:14.490 --> 00:15.410
your model.

00:15.420 --> 00:19.770
So there's sort of validation on the data you're saving.

00:20.040 --> 00:21.960
Now let's see how that is going to look.

00:21.960 --> 00:28.590
It's going to look actually almost the same as the example we have here with the title and these other

00:28.590 --> 00:29.670
properties.

00:29.910 --> 00:37.290
So we are going to write out first let's make a model folder, let's call it model.

00:38.010 --> 00:41.430
And in here we are going to have the model file.

00:41.430 --> 00:48.690
So we have a convention says that the model files usually have a capital letter in the start.

00:48.690 --> 00:58.980
So we call this one for listing dot JS and then in here inside the listing JS we import Mongoose.

01:03.330 --> 01:10.140
And then we can say const listing schema equals new mongoose.

01:11.000 --> 01:12.530
Dot schema.

01:14.910 --> 01:18.350
And then in here we have the different properties.

01:18.360 --> 01:23.670
So we have the title property and we have the date posted.

01:24.780 --> 01:27.840
Which is a date type interface.

01:27.840 --> 01:29.880
Well, it's a type of date.

01:30.000 --> 01:34.500
And then we have the neighborhood, so neighborhood.

01:38.870 --> 01:40.530
And that's a type string.

01:40.550 --> 01:43.610
Then we have the URL, also a string.

01:43.640 --> 01:45.140
The job description.

01:46.990 --> 01:50.050
It's a string and the compensation.

01:50.680 --> 01:52.660
We keep that as a string also.

01:54.610 --> 02:03.610
Now we simply create this listing model from Mongoose that we can manipulate inside of our JavaScript.

02:03.610 --> 02:04.750
So that looks like this.

02:04.780 --> 02:08.020
We say const listing mongoose.

02:09.150 --> 02:10.410
Dot model.

02:10.500 --> 02:15.030
Then we have the listing and then we say listing schema.

02:16.510 --> 02:23.100
Now we export the the model so we can import it in the other files inside JavaScript.

02:25.580 --> 02:29.300
So now we have defined a schema for all of this data.

02:29.300 --> 02:32.900
We're going to make this model with using mongoose.

02:33.020 --> 02:40.730
So this is different compared to using a raw MongoDB driver where we can simply just pass in any JavaScript

02:40.730 --> 02:41.520
object.

02:41.540 --> 02:47.240
But in this case, we're going to have some kind of validation for our model and we know exactly what

02:47.240 --> 02:49.490
kind of data we are saving.

02:51.040 --> 02:56.620
Now let's go on and try to use and save this model inside of our Index.js file.
