In this video, we are going to prevent the session being lost upon every restarting of the server and
we are going to save the session inside our database.
So how are we going to achieve that?
We are going to use a package called Connect Mongo, so let's make use of NPM.
I connect the mongo and let's hit enter.
All right.
The package has finished installing, so let me restart the server and inside the server file.
That's where we are going to configure that.
So let's go ahead and then require the package as Mongo store.
Is equal to required.
Connect Mongol.
Perfect.
So for the session you are going to add additional property for store.
And are going to make use of new.
And then the mongoose stole the package that we just installed.
And for this you're going to pass in some configuration and the first property is called mongo URL,
meaning that our connection string and we have access on the process dot and v dot mongo.
You are al as mongo you are.
Let's make sure that we are using the right property here.
So you're going to be as mongo.
You are error.
So with this one we are done.
The next one going to be when do you want to expire the session?
So the property is called pt L and if want to expire the session in a day, you are going to make use
of 24 by 60 by 60.
And this is one day.
So now if I look in, let's see the changes that we are going to see.
Look in.
And we have the user back.
And if you check our database, let's right click and refresh.
If we open our database name, you can see we have a new collection called Searching, and we got this
one because of the package we install called Connect Mongo.
And if you open that, we have one document and that is a log in user session and you can see we have
the date the session will expire.
So with this one, if I make a request to the profile, even if I restart the server, I'm going to
have the log in user.
So let's log in again and let me go to the profile.
And next is let's restart the server shut down and let's restart it and let me hit the endpoint, the
profile and let's see.
And there you go.
You can see that you go by the response, meaning that the session is being persisted.
So upon every restarting, we are going to lose the session.
All right.
With this one, the next video, let's go ahead and implement the actual five page.