In this video.
Before we can create a record and save into MongoDB, we need to finish up our steps.
And the one that has left is what we call model.
So what is a model?
A model is a class with which we construct documents, meaning that model helps us to create, document
and save into MongoDB.
So how can we create it?
So let's go ahead and create our model and here we go, const and then the name of the model.
We often use uppercase student because model is a class of which we can create instances of student
from this model.
So here we go is equal to mongoose, the package that we required here.
And on that we have a method called model.
And that is it.
Before we continue on back to my compass, I have changed the theme of my compass.
So if you want to change it, click on compass and theme and you can select light theme or dot team.
Sometimes I can change a light theme or dark theme depending on my mood.
Okay.
So and also I have trashed all the data base with the exception of the default one.
So to be able to delete a database, click on this icon.
And sometimes if you are deleting, we get some message that we don't have permission to take this operation.
So to give permission to delete a database inside your MongoDB dashboard, click on database access
and then click on edit.
And down here you can see that we have built in rows.
By default it will give you read and write, so click on the dropdown and this is a default, right?
Or privilege.
So click on at last admin and then click on update user and then you can delete database.
So here I don't have any database inside.
So back to my model.
The next argument to take is going to be the name of my collection and the name.
Our path in here is going to be available inside my MongoDB dashboard.
So here we often use uppercase students, but for this one, as soon as we compile it, the name of
the first segment is going to be singular and then privileges it.
Meaning we're going to add X to each of the variable we pass in here.
And the next segment is the schema that we have defined, which is student schema.
So we pass in here as student schema and that is it.
So with this one, I can interact with MongoDB using this model.
So anywhere in my application I refer to this.
It means I'm making use of student model or collection.
Let me save it.
And now back to the terminal here.
Let me click the console and run the file again.
And let's see that MongoDB will be connected.
Okay, good.
It has been connected.
And back to my compass.
Let me refresh it.
And now let's see something.
Well, I believe that we are not going to see the collection because we haven't saved any data yet.
So it's still loading and there will be no collection here.
So let's get back to the code.
And then in this video, let's see how we can create first to the end and visualize it inside our dashboard
using Mongoose in the next video.