All right, so when the previous video we talked about set and save.
And now it's time to explain the rest of the.
So first of all, I want to explain the update one minute.
But before that, I want to add one property to my schema, so let's go over to the students file and
add the student number of property as a number.
And flip on back to the update file.
So update one method is similar to the find one method you may be thinking, I mean, it only updates
the record, which is the first match with our criteria.
So I'm going to add new Jason Var. here, Jason, to.
Create a new record with the name of Jason.
This time, I'm going to add student number of property to two of them.
First one is student number 2500.
A second is student number 3500.
After that, save Jason, too, as well.
Sides, in order to see in detail, I'm going to add console log here for Jason and Jason to.
All right, and now it's time to create another IT block.
But before that, I want to make this block comment because before.
Each block runs before each block runs as well.
So kind of makes our code a little complicated.
Kind of messy, but anyway, let's continue.
Say it and say, update one of the Jayson's.
This time I want to write a sink, a weight.
That's my function here, so we'll write a song and arrow function.
Remember that when we define an async, await function, we assign our promise to a variable.
So I say consed student equals student tot update one.
Now, this time I want to change the first Jamesons student number to 3000.
Now, in order to do this, I'll write my criteria first name, Jason, and the property that I want
to change, student number 3000.
Now, in order to check my records, first of all, I should take them and do my test.
It's hard to find a new variable as Const Brez equals a weight student, not find with an empty array
because I want to bring all of them.
And finally, I will write my assertion.
I assert that the number of students of the first, Jason, changed into 3000.
So.
Right.
Assert Ri's zero dot student number.
And I expect that there will be equal to 3000.
OK, now I hope it will pass and I want to see an updated record in my console as well, so say console
log revs, OK, so everything looks fine.
Let's run it.
OK, so see how all my tests are passed and you can see that the first Jason student number has been
changed to 3000.
All right, so that's the.
Now, let's figure out how to use the update, many method.
And as you might gather by the name, well, you can change as many records as you want, even all of
them, as long as they match with a filter that you set up.
So I'm just going to copy this block again and make this blog comment.
So after that, I'll just change here, update, Jason.
And this part update many.
OK, so this time I expect that all the Jasons student numbers should change to 3000 now.
I know when we're walking on such a small number of files, it doesn't really make a whole lot of sense.
But you're going to see how the method works anyway.
All right, so that's enough for now.
I will also assert that the second Jason's number will change, so I'm going to add in and Rezwan,
that student number equals 3000 here.
And that's OK.
OK, so let's run the test again, see if our test passes.
Well, what do you know, everything is fine, my test passes and the student numbers have been changed
to 3000.
So those are the important update methods and we finish all of the CRUD operations, well done.
But don't worry, there's more.
So we'll continue in the next section.