1
00:00:06,390 --> 00:00:07,530
Welcome back.

2
00:00:07,560 --> 00:00:12,680
In this video, let's see how we can update record Inside Mongoose.

3
00:00:12,690 --> 00:00:20,190
So let's go to the documentation and let's find the method called find by ID and update.

4
00:00:20,550 --> 00:00:27,210
You can see we have one method call find by one and update.

5
00:00:27,330 --> 00:00:37,320
So for this one we can use to find any document with any field, it can be named Title H or ID and we

6
00:00:37,320 --> 00:00:43,740
have one called find by ID and update is also work in the same way.

7
00:00:44,040 --> 00:00:50,580
So let's work with the find one and update and see how it's going to work.

8
00:00:50,580 --> 00:00:57,210
So let's click on find one and update or we can set it here as find one and update.

9
00:00:57,210 --> 00:00:58,710
So here we go.

10
00:00:59,010 --> 00:01:03,870
And it will see that for this one it is in couple of arguments.

11
00:01:04,410 --> 00:01:07,170
The first one going to be the query we want to find.

12
00:01:07,170 --> 00:01:12,270
It can be a title, it can be ID and then the doc and the additional option.

13
00:01:12,280 --> 00:01:13,020
I'll start.

14
00:01:13,020 --> 00:01:17,910
So let's see how we are going to implement it inside that.

15
00:01:18,150 --> 00:01:21,210
So it provides additional option as new.

16
00:01:21,210 --> 00:01:29,610
It simply means that we want to see the updated data on the fly as soon as is being saved without refreshing.

17
00:01:29,760 --> 00:01:36,810
So this option is really crucial or important and we see that default false and we change in version

18
00:01:36,810 --> 00:01:37,560
point oh.

19
00:01:37,800 --> 00:01:44,430
So I think with the new version, there is no need to provide the new because it should be updated and

20
00:01:44,430 --> 00:01:47,280
we are using version 6.5.3.

21
00:01:47,280 --> 00:01:50,850
So I think there's no need to provide a new argument.

22
00:01:50,850 --> 00:01:52,830
So let's see how you're going to achieve that.

23
00:01:53,040 --> 00:02:03,420
So back here, let me comment this one and let me bring this comment here and say update record.

24
00:02:04,080 --> 00:02:07,290
So let's see how we are going to update this one.

25
00:02:07,290 --> 00:02:10,800
So we bring in the student model on that.

26
00:02:10,800 --> 00:02:15,900
We are going to use find one and update as soon as I type in fine.

27
00:02:15,900 --> 00:02:24,750
I see all the method that I can use on that model and the one that I want is find one and update which

28
00:02:24,750 --> 00:02:31,020
is this one and next is you pass in the options or the configuration.

29
00:02:31,290 --> 00:02:33,360
The first one going to be the query.

30
00:02:33,630 --> 00:02:43,470
So let's find the student by name of John as that and a nest egg means pass in is a field that you want

31
00:02:43,470 --> 00:02:44,340
to update.

32
00:02:44,430 --> 00:02:48,600
So I want to update the age to 35.

33
00:02:49,020 --> 00:02:55,830
The NEST agreement going to be option like we saw in the documentation and then the first one going

34
00:02:55,830 --> 00:03:03,420
to be new to true meaning that we want to see the updated one on the fly as soon as we save it.

35
00:03:03,870 --> 00:03:12,330
So let's handle the premise then and then we have the student as the student, or you can make it as

36
00:03:12,360 --> 00:03:19,310
updated student and let me catch any error if there is going to be an error here also.

37
00:03:20,320 --> 00:03:22,460
All right, then.

38
00:03:22,460 --> 00:03:24,830
Let me move this one and let's see.

39
00:03:25,100 --> 00:03:27,320
So back to the terminal here.

40
00:03:27,620 --> 00:03:33,530
Let me clear the terminal and let me run the file again instead of 20 of the age.

41
00:03:33,530 --> 00:03:36,950
Now we have 30, meaning that it has been updated.

42
00:03:36,950 --> 00:03:43,550
Let's try to remove the new and let's see if you're going to see the updated one based on what we've

43
00:03:43,550 --> 00:03:44,150
learned.

44
00:03:44,660 --> 00:03:44,990
Okay.

45
00:03:45,050 --> 00:03:47,930
So now let me change the age to 40 years.

46
00:03:50,110 --> 00:03:50,770
Here we go.

47
00:03:50,770 --> 00:03:52,360
Back to the terminal here.

48
00:03:52,390 --> 00:03:55,570
Let me clear it and let me run it again.

49
00:03:55,840 --> 00:04:03,070
I could see that you couldn't get the updated one, but inside our DB, if you refresh it, we are going

50
00:04:03,070 --> 00:04:05,230
to see that it is 40.

51
00:04:05,960 --> 00:04:11,750
And you can see that we have it here, but we didn't see it as a response.

52
00:04:11,780 --> 00:04:15,270
That's why the new equipment is important.

53
00:04:15,290 --> 00:04:20,810
So let me bring back the new here and let me change this one to, let's say, 50 years.

54
00:04:20,959 --> 00:04:23,760
We also have another method for updating.

55
00:04:23,780 --> 00:04:28,820
So let me copy this one and comment it and the difference here.

56
00:04:28,820 --> 00:04:32,240
Can I be fine by ID and update?

57
00:04:32,390 --> 00:04:39,130
And this one finds only the ID, so find by I.D. and update.

58
00:04:39,140 --> 00:04:42,740
So here we pass in the ID as a student.

59
00:04:42,740 --> 00:04:46,480
So let's find the ID back to my campus here.

60
00:04:46,490 --> 00:04:52,370
I think I want to find a manual here so I'll copy the ID and back to my code.

61
00:04:52,370 --> 00:04:56,450
Here, let me replace it with that and then come on, separate it.

62
00:04:56,540 --> 00:04:58,220
Now back to the terminal.

63
00:05:00,080 --> 00:05:07,370
Let me run it again and let's see if I'm going to get Emanuel to be updated.

64
00:05:07,520 --> 00:05:11,330
And you can see that Emanuel Fair has been updated.

65
00:05:11,600 --> 00:05:12,170
All right.

66
00:05:12,170 --> 00:05:18,350
So these are the common methods you are going to use a lot find by ID and update more than the fine

67
00:05:18,350 --> 00:05:19,940
one and update.

