We come back in this video.
Let's see how we can find a single record that is a single user.
So back to the documentation.
We have couple of methods to get it done.
We can use find by ID or find one.
So under queries, we have a method called find one to find a single record.
And you also have one called Find by ID so we can search here sets find by ID and here you go, model
dot find by ID.
If you click on that, look at the agreement.
It takes pass in what is called any meaning any property.
It can be name, it can be title, it can be ID, but most often you use the ID because the ID is unique
because you may have a record with the same name or title.
In that case we are going to get not what you want.
So ideally we use the ID to find a particular user, so let's go ahead and do that.
So back to the code here and let me comment this one and let's have a beautiful comment here.
Says, find a single record.
So you bring in the student model dot find by ID, fine by ID and here I'll pass in what I want to find.
That is an ID so here I can provide and that's called ID and then the name of the ID or I can quickly
pass in the ID.
If I'm using the ID, I can pass in here directly.
So back to my terminal here.
I want to find this student by this ID called John, so I'll copy the ID here and now back to my method
here.
I will paste it inside and let me handle the promise as that is going to be the actual student.
All right.
And then let me console.log the student.
If something goes wrong again, let's catch it as the error.
All right.
So let's go ahead and run the file and let's see if you're going to get that particular student.
And indeed we have got the student with the ID of this.
We can also use find one to find a single record.
So here we go.
So here, let me comment this one.
The difference here is going to be the method going to be find one and find one pass in object with
key value per.
So here you're going to make find one.
Let's say the age or the name to be more specific, is equal to John.
So let's save it.
And now back to the terminal.
Let me run the file again and let's see the result.
And we have John.
Indeed.
So this how we can fetch a single record.