1
00:00:07,070 --> 00:00:08,900
Come back in this video.

2
00:00:08,900 --> 00:00:12,630
Let's see how we can update a document.

3
00:00:12,650 --> 00:00:19,260
So let's say that after one year, I want to change my name, to change how I'm going to do it.

4
00:00:19,280 --> 00:00:20,460
Let's see how.

5
00:00:20,480 --> 00:00:23,710
So back to Visual City Code as always.

6
00:00:23,720 --> 00:00:30,260
Let's comment this one and let's have a beautiful comment here says update record.

7
00:00:30,590 --> 00:00:32,210
So here we go.

8
00:00:32,509 --> 00:00:37,620
The first step is I need to find the particular student I want to update.

9
00:00:37,640 --> 00:00:42,530
And after that, I need to find the fields that I want to update.

10
00:00:42,800 --> 00:00:44,480
Do you remember?

11
00:00:44,480 --> 00:00:48,170
And API creation using the file system.

12
00:00:48,170 --> 00:00:54,820
I told you that if you get to MongoDB, if you want to update a record, it's going to be pretty easy.

13
00:00:54,830 --> 00:00:56,270
This is the time.

14
00:00:56,390 --> 00:01:02,570
But when we're dealing with the files to be able to update a record, we went through a couple of steps,

15
00:01:02,570 --> 00:01:07,340
so let's see how easy we are going to update record inside MongoDB.

16
00:01:07,370 --> 00:01:13,030
First step is going to find it and then get a property you want to update and that is all.

17
00:01:13,040 --> 00:01:15,830
So let's write two lines of code to get it done.

18
00:01:15,830 --> 00:01:16,910
So here we go.

19
00:01:16,940 --> 00:01:19,250
Update Record Const.

20
00:01:20,530 --> 00:01:21,680
Updated.

21
00:01:23,080 --> 00:01:31,450
Student is equal to a weight and then the student collection which is this one on that we have what

22
00:01:31,450 --> 00:01:33,820
is called updates one.

23
00:01:33,820 --> 00:01:42,370
We have update one and update money one, updates a single record and many updates multiple records.

24
00:01:42,370 --> 00:01:48,250
So let's stick to update one and this one, it takes in two arguments.

25
00:01:48,250 --> 00:01:51,910
One is the user or the record we want to find.

26
00:01:52,090 --> 00:01:57,970
So update works like this combination of find with some additional properties.

27
00:01:57,970 --> 00:02:05,380
So let's say that I want to find a student by name Emmanuel and this is a student I want to update.

28
00:02:05,530 --> 00:02:09,669
The next element is what properties I want to update.

29
00:02:09,669 --> 00:02:14,500
I can update the city or the name, so the choice is mine.

30
00:02:14,740 --> 00:02:18,730
So I'll provide object and let me expand it like that.

31
00:02:18,730 --> 00:02:23,110
And here I'm going to provide dollar sign set.

32
00:02:24,500 --> 00:02:32,480
As the name implies, for setting a new property and colour on objects and the fields that we want to

33
00:02:32,480 --> 00:02:33,190
update.

34
00:02:33,200 --> 00:02:37,940
I want to update my name to change one.

35
00:02:38,660 --> 00:02:45,650
Now, with this one, save it and let's go ahead and console.log the updated student.

36
00:02:46,970 --> 00:02:53,780
All right, let's get back to the terminal, play the terminal here and let's restart.

37
00:02:54,140 --> 00:03:01,910
And you can see that acknowledged, if I check my MongoDB collection, you can see that the name has

38
00:03:01,910 --> 00:03:03,140
been updated.

39
00:03:03,140 --> 00:03:05,300
Let's refresh it and let's see.

40
00:03:07,050 --> 00:03:15,540
So let's look through now instead of Yemen where I see up here, that's how we update the last crowd

41
00:03:15,600 --> 00:03:18,350
operation is how we can delete.

42
00:03:18,360 --> 00:03:22,260
But before we continue, we can also update multiple fields.

43
00:03:22,500 --> 00:03:26,340
So let's say I want to change my city to Accra.

44
00:03:26,370 --> 00:03:33,750
Now, if I save it and now back to the terminal and I restart it, you're going to see that the name

45
00:03:33,750 --> 00:03:40,140
of Acura has been updated and we have acknowledged meaning everything is perfect.

46
00:03:40,260 --> 00:03:43,560
So if you check your dashboard, you're going to see the updated one.

47
00:03:43,590 --> 00:03:47,490
The last operation is how we can delete a record.

48
00:03:47,490 --> 00:03:49,440
So here are going to be delete.

49
00:03:49,470 --> 00:03:51,960
Let's get into that in the next video.

