1
00:00:01,380 --> 00:00:10,050
In this video, we are going to prevent the session being lost upon every restarting of the server and

2
00:00:10,050 --> 00:00:13,490
we are going to save the session inside our database.

3
00:00:13,500 --> 00:00:15,600
So how are we going to achieve that?

4
00:00:15,720 --> 00:00:22,620
We are going to use a package called Connect Mongo, so let's make use of NPM.

5
00:00:22,620 --> 00:00:28,380
I connect the mongo and let's hit enter.

6
00:00:29,390 --> 00:00:29,930
All right.

7
00:00:29,930 --> 00:00:36,540
The package has finished installing, so let me restart the server and inside the server file.

8
00:00:36,560 --> 00:00:38,840
That's where we are going to configure that.

9
00:00:38,840 --> 00:00:44,150
So let's go ahead and then require the package as Mongo store.

10
00:00:45,180 --> 00:00:47,940
Is equal to required.

11
00:00:48,780 --> 00:00:50,220
Connect Mongol.

12
00:00:50,940 --> 00:00:51,780
Perfect.

13
00:00:51,780 --> 00:00:57,330
So for the session you are going to add additional property for store.

14
00:00:58,130 --> 00:01:00,680
And are going to make use of new.

15
00:01:00,680 --> 00:01:05,600
And then the mongoose stole the package that we just installed.

16
00:01:06,020 --> 00:01:12,950
And for this you're going to pass in some configuration and the first property is called mongo URL,

17
00:01:12,980 --> 00:01:21,510
meaning that our connection string and we have access on the process dot and v dot mongo.

18
00:01:21,530 --> 00:01:24,870
You are al as mongo you are.

19
00:01:25,010 --> 00:01:29,840
Let's make sure that we are using the right property here.

20
00:01:29,840 --> 00:01:32,270
So you're going to be as mongo.

21
00:01:32,270 --> 00:01:33,320
You are error.

22
00:01:33,440 --> 00:01:35,800
So with this one we are done.

23
00:01:35,810 --> 00:01:40,490
The next one going to be when do you want to expire the session?

24
00:01:40,730 --> 00:01:47,810
So the property is called pt L and if want to expire the session in a day, you are going to make use

25
00:01:47,810 --> 00:01:51,440
of 24 by 60 by 60.

26
00:01:53,070 --> 00:01:55,380
And this is one day.

27
00:01:57,870 --> 00:02:03,360
So now if I look in, let's see the changes that we are going to see.

28
00:02:03,690 --> 00:02:04,890
Look in.

29
00:02:05,890 --> 00:02:08,020
And we have the user back.

30
00:02:08,020 --> 00:02:12,310
And if you check our database, let's right click and refresh.

31
00:02:13,380 --> 00:02:20,730
If we open our database name, you can see we have a new collection called Searching, and we got this

32
00:02:20,730 --> 00:02:25,220
one because of the package we install called Connect Mongo.

33
00:02:25,230 --> 00:02:33,060
And if you open that, we have one document and that is a log in user session and you can see we have

34
00:02:33,060 --> 00:02:35,670
the date the session will expire.

35
00:02:35,970 --> 00:02:43,350
So with this one, if I make a request to the profile, even if I restart the server, I'm going to

36
00:02:43,350 --> 00:02:45,570
have the log in user.

37
00:02:46,140 --> 00:02:50,700
So let's log in again and let me go to the profile.

38
00:02:51,090 --> 00:02:59,460
And next is let's restart the server shut down and let's restart it and let me hit the endpoint, the

39
00:02:59,470 --> 00:03:00,870
profile and let's see.

40
00:03:01,740 --> 00:03:03,040
And there you go.

41
00:03:03,060 --> 00:03:08,770
You can see that you go by the response, meaning that the session is being persisted.

42
00:03:08,790 --> 00:03:13,270
So upon every restarting, we are going to lose the session.

43
00:03:13,290 --> 00:03:13,830
All right.

44
00:03:13,830 --> 00:03:19,530
With this one, the next video, let's go ahead and implement the actual five page.

