Now it's time for us to write out this schema for our mongoose model.
So Mongoose is special compared to the raw MongoDB driver in the sense that you define a schema for
your model.
So there's sort of validation on the data you're saving.
Now let's see how that is going to look.
It's going to look actually almost the same as the example we have here with the title and these other
properties.
So we are going to write out first let's make a model folder, let's call it model.
And in here we are going to have the model file.
So we have a convention says that the model files usually have a capital letter in the start.
So we call this one for listing dot JS and then in here inside the listing JS we import Mongoose.
And then we can say const listing schema equals new mongoose.
Dot schema.
And then in here we have the different properties.
So we have the title property and we have the date posted.
Which is a date type interface.
Well, it's a type of date.
And then we have the neighborhood, so neighborhood.
And that's a type string.
Then we have the URL, also a string.
The job description.
It's a string and the compensation.
We keep that as a string also.
Now we simply create this listing model from Mongoose that we can manipulate inside of our JavaScript.
So that looks like this.
We say const listing mongoose.
Dot model.
Then we have the listing and then we say listing schema.
Now we export the the model so we can import it in the other files inside JavaScript.
So now we have defined a schema for all of this data.
We're going to make this model with using mongoose.
So this is different compared to using a raw MongoDB driver where we can simply just pass in any JavaScript
object.
But in this case, we're going to have some kind of validation for our model and we know exactly what
kind of data we are saving.
Now let's go on and try to use and save this model inside of our Index.js file.