All right.
And up next, let's set up structure for our data.
So essentially in this application, we will be creating jobs.
Correct.
And each job is going to have position company where it's located as well as job status and job type.
And in order to set up the structure first, we'll need to create a models folder since there's going
to be multiple models.
And we'll start with the job model.
So in here, let's create a new file and let's go with Job.
Model.
JS.
First we want to grab the mongoose.
So same deal.
Effectively we import mongoose from Mongoose.
Then let's create a schema.
So first we need to come up with a name.
In my case, it's going to be job schema and eventually there's also going to be a user schema and eventually
we'll connect it to since each job belongs to a specific user and we want to go with new Mongoose and
then schema.
So that's the name.
And then inside of the schema we want to pass in the object.
And then one by one we'll set up the properties just like we do in normal JavaScript object.
Of course, in this case we're just setting up the properties for our database instance and we'll start
here with a simple one.
So I'm going to go with Company String now.
Of course there are multiple value types, but I'm not going to cover each and every option over here
for the type.
Basically, as we're working on a project, you'll see some other options as well.
So company string.
Pretty straightforward.
So the same thing we want to do with position.
So that's going to be my second property over here.
Then if we have more complex setup, we can create a key as a object.
What am I talking about?
Well, let's say for job status.
Notice over here how we have these three values.
So it might be pending interview or declined.
So instead of just setting it equal to string number or whatever, I'm going to go with job status,
then I'll create an object.
And first, what is going to be the type?
Well, same deal.
It's going to be string.
Then we're going to go with enum and essentially enum data type represents a field with predefined set
of values like you just saw.
There's a select box on the front end which allows to have interview declined and pending and in here
we go with enum.
And we provide those values.
So essentially it will send a value that doesn't match anything.
What we have here in the array, mongoose is just going to yell at us.
And we won't be able to submit the job.
Well, then we want to go with declined.
And as a side note, eventually we will set them up as constants, but not for now.
Let's go here with pending as well.
And then we also can set up the default value.
And we just provide the default property.
In my case, I'm going to go with pending here.
Let's save it.
Now we have the job status.
Now the job type also is going to be no, because again, we have this select box with these values.
And therefore.
Basically we just want to copy this, so copy and paste.
Let's change the value around instead of job.
Status is going to be job type, still string, but these values are going to be different.
So here we're looking for full time.
Then part time.
Part time and an internship.
And as far as the default one.
I think I'm just going to go with full time.
Then we also have job location, which essentially just represents where the job is located.
And as far as the front end, we will use the user's location in order to provide the value.
But when it comes to our database, basically we just want to provide type string.
So it's going to be a string and default value just in case it's not provided.
We're going to go here with my city.
So we have the schema and before we set up the model, essentially our collection right after the first
object, we want to make a comma and another one.
And here we just want to go with timestamps and set it equal to true.
So if we add this property with this value, essentially whenever we will create the instance, not
only will get the IDs which MongoDB sets up by default, but we'll also have this createdat and Updatedat
fields and pretty much every time we'll do something with our instance, we'll get the correct values,
something we'll cover a little bit later, but very, very nifty.
And also we want to export this, so we're going to go with export default.
Then mongoose.
So our instance then model and this is where we need to create a name for our model.
Effectively we're creating a collection and whenever you hear a word collection, think table.
So this is where we'll group all of our instances.
And in my case, I'm going to go with Job and we want to provide the job schema.
We'll save this over here.
And up next, we'll work on create job Controller.
Only in this case, we will save the job in a database.