1
00:00:06,790 --> 00:00:08,910
We come back in this video.

2
00:00:08,910 --> 00:00:14,700
Let's see how we can find a single record that is a single user.

3
00:00:14,880 --> 00:00:17,340
So back to the documentation.

4
00:00:17,340 --> 00:00:19,800
We have couple of methods to get it done.

5
00:00:19,800 --> 00:00:23,490
We can use find by ID or find one.

6
00:00:23,580 --> 00:00:30,030
So under queries, we have a method called find one to find a single record.

7
00:00:30,060 --> 00:00:42,960
And you also have one called Find by ID so we can search here sets find by ID and here you go, model

8
00:00:42,960 --> 00:00:44,720
dot find by ID.

9
00:00:44,730 --> 00:00:47,160
If you click on that, look at the agreement.

10
00:00:47,160 --> 00:00:51,830
It takes pass in what is called any meaning any property.

11
00:00:51,840 --> 00:01:00,300
It can be name, it can be title, it can be ID, but most often you use the ID because the ID is unique

12
00:01:00,300 --> 00:01:03,540
because you may have a record with the same name or title.

13
00:01:03,540 --> 00:01:07,350
In that case we are going to get not what you want.

14
00:01:07,350 --> 00:01:14,340
So ideally we use the ID to find a particular user, so let's go ahead and do that.

15
00:01:14,340 --> 00:01:22,410
So back to the code here and let me comment this one and let's have a beautiful comment here.

16
00:01:22,410 --> 00:01:26,880
Says, find a single record.

17
00:01:27,270 --> 00:01:37,890
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.

18
00:01:37,890 --> 00:01:47,070
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

19
00:01:47,070 --> 00:01:49,140
pass in the ID.

20
00:01:49,170 --> 00:01:52,740
If I'm using the ID, I can pass in here directly.

21
00:01:52,740 --> 00:01:54,780
So back to my terminal here.

22
00:01:54,930 --> 00:02:03,810
I want to find this student by this ID called John, so I'll copy the ID here and now back to my method

23
00:02:03,810 --> 00:02:04,170
here.

24
00:02:04,170 --> 00:02:12,750
I will paste it inside and let me handle the promise as that is going to be the actual student.

25
00:02:14,540 --> 00:02:15,460
All right.

26
00:02:15,460 --> 00:02:18,880
And then let me console.log the student.

27
00:02:21,680 --> 00:02:28,310
If something goes wrong again, let's catch it as the error.

28
00:02:32,930 --> 00:02:33,380
All right.

29
00:02:33,380 --> 00:02:39,020
So let's go ahead and run the file and let's see if you're going to get that particular student.

30
00:02:41,550 --> 00:02:47,730
And indeed we have got the student with the ID of this.

31
00:02:48,120 --> 00:02:51,840
We can also use find one to find a single record.

32
00:02:51,840 --> 00:02:52,860
So here we go.

33
00:02:52,890 --> 00:02:55,530
So here, let me comment this one.

34
00:02:55,920 --> 00:03:04,590
The difference here is going to be the method going to be find one and find one pass in object with

35
00:03:04,590 --> 00:03:05,960
key value per.

36
00:03:05,970 --> 00:03:07,950
So here you're going to make find one.

37
00:03:07,950 --> 00:03:14,370
Let's say the age or the name to be more specific, is equal to John.

38
00:03:14,850 --> 00:03:16,260
So let's save it.

39
00:03:16,260 --> 00:03:18,360
And now back to the terminal.

40
00:03:18,690 --> 00:03:22,860
Let me run the file again and let's see the result.

41
00:03:22,860 --> 00:03:25,230
And we have John.

42
00:03:25,230 --> 00:03:26,230
Indeed.

43
00:03:26,250 --> 00:03:30,030
So this how we can fetch a single record.

