Come back in this video.
Let's see how we can update a document.
So let's say that after one year, I want to change my name, to change how I'm going to do it.
Let's see how.
So back to Visual City Code as always.
Let's comment this one and let's have a beautiful comment here says update record.
So here we go.
The first step is I need to find the particular student I want to update.
And after that, I need to find the fields that I want to update.
Do you remember?
And API creation using the file system.
I told you that if you get to MongoDB, if you want to update a record, it's going to be pretty easy.
This is the time.
But when we're dealing with the files to be able to update a record, we went through a couple of steps,
so let's see how easy we are going to update record inside MongoDB.
First step is going to find it and then get a property you want to update and that is all.
So let's write two lines of code to get it done.
So here we go.
Update Record Const.
Updated.
Student is equal to a weight and then the student collection which is this one on that we have what
is called updates one.
We have update one and update money one, updates a single record and many updates multiple records.
So let's stick to update one and this one, it takes in two arguments.
One is the user or the record we want to find.
So update works like this combination of find with some additional properties.
So let's say that I want to find a student by name Emmanuel and this is a student I want to update.
The next element is what properties I want to update.
I can update the city or the name, so the choice is mine.
So I'll provide object and let me expand it like that.
And here I'm going to provide dollar sign set.
As the name implies, for setting a new property and colour on objects and the fields that we want to
update.
I want to update my name to change one.
Now, with this one, save it and let's go ahead and console.log the updated student.
All right, let's get back to the terminal, play the terminal here and let's restart.
And you can see that acknowledged, if I check my MongoDB collection, you can see that the name has
been updated.
Let's refresh it and let's see.
So let's look through now instead of Yemen where I see up here, that's how we update the last crowd
operation is how we can delete.
But before we continue, we can also update multiple fields.
So let's say I want to change my city to Accra.
Now, if I save it and now back to the terminal and I restart it, you're going to see that the name
of Acura has been updated and we have acknowledged meaning everything is perfect.
So if you check your dashboard, you're going to see the updated one.
The last operation is how we can delete a record.
So here are going to be delete.
Let's get into that in the next video.