1
00:00:08,720 --> 00:00:09,920
Welcome back.

2
00:00:09,950 --> 00:00:14,000
In this video, let's see how we can carry a database.

3
00:00:14,000 --> 00:00:19,100
That is how we can find all students by a specific name.

4
00:00:19,310 --> 00:00:27,020
So let's say that in our database, we want to find all student who is from a specific location.

5
00:00:27,050 --> 00:00:30,440
We can do that using what is called find.

6
00:00:30,890 --> 00:00:36,350
Meaning find is going to return all records with specific query.

7
00:00:36,530 --> 00:00:42,680
And if we want to find a single user, we are going to use a different method called find one.

8
00:00:43,070 --> 00:00:45,590
And this is what we call query.

9
00:00:45,620 --> 00:00:50,750
We are going to query our database to retrieve a specific data that we need.

10
00:00:50,780 --> 00:00:53,360
So let me comment this one.

11
00:00:53,780 --> 00:01:01,010
So let's say find a student by name, Emmanuel.

12
00:01:01,220 --> 00:01:02,090
The first step.

13
00:01:02,090 --> 00:01:03,020
So let's see.

14
00:01:03,050 --> 00:01:09,830
Com found student equal to a weight.

15
00:01:09,830 --> 00:01:17,540
And then my student collection on that we have a method called find what you see we have find and then

16
00:01:17,540 --> 00:01:18,580
find one.

17
00:01:18,590 --> 00:01:23,350
What is a difference is well let's take to the find one.

18
00:01:23,360 --> 00:01:26,300
So here we go find one.

19
00:01:26,300 --> 00:01:33,410
Our pass in the argument which is called the query as objects and provide the property name.

20
00:01:33,710 --> 00:01:40,670
So make sure that the property name exists on the document because we have name on the document here.

21
00:01:40,970 --> 00:01:46,010
So here I want to find a student by name who is Emmanuel.

22
00:01:46,040 --> 00:01:50,900
Now, if I console.log, the found student.

23
00:01:50,900 --> 00:01:52,760
Found student.

24
00:01:54,560 --> 00:01:58,850
Let's go ahead and then run and let's see what you're going to get.

25
00:01:59,270 --> 00:02:01,940
And indeed I get the result.

26
00:02:01,970 --> 00:02:11,030
Emmanuel What about if I provide a name which is not in our record, for example, then so save it and

27
00:02:11,030 --> 00:02:12,550
now let's check it out here.

28
00:02:12,560 --> 00:02:16,040
Click the console and let's run the file again.

29
00:02:16,250 --> 00:02:21,500
You can see I got NA meaning that user does not exist.

30
00:02:21,530 --> 00:02:23,480
That is how we make it.

31
00:02:23,660 --> 00:02:28,460
The next step is I want to find all student with specific name.

32
00:02:28,700 --> 00:02:30,500
Okay, so here we go.

33
00:02:30,530 --> 00:02:32,960
The first one is find a student by name.

34
00:02:32,960 --> 00:02:35,260
That is Emmanuel and he's going to be fine.

35
00:02:35,270 --> 00:02:37,520
All student who is from?

36
00:02:38,470 --> 00:02:40,960
Kumasi the city name.

37
00:02:41,520 --> 00:02:46,090
You see that in our database we have to student who is from Kumasi.

38
00:02:46,120 --> 00:02:48,890
The first one is John and then Emmanuel.

39
00:02:48,910 --> 00:02:52,630
So when I make that query, I'm going to get these two students.

40
00:02:52,630 --> 00:02:54,610
So here we go.

41
00:02:54,910 --> 00:03:02,440
So I'll provide our bring in the same command here and then down here, paste it here and change this

42
00:03:02,440 --> 00:03:05,010
one to find has that.

43
00:03:05,020 --> 00:03:07,180
So let me comment this one.

44
00:03:07,180 --> 00:03:11,300
And here are going to be students, plural for students.

45
00:03:11,330 --> 00:03:11,950
Okay.

46
00:03:11,950 --> 00:03:15,760
So here are going to be the student.

47
00:03:16,060 --> 00:03:19,180
So I want to find all student by city.

48
00:03:19,180 --> 00:03:25,550
So here I'm going to be city and the city name going to be as Kumasi.

49
00:03:26,050 --> 00:03:26,530
All right.

50
00:03:26,530 --> 00:03:27,810
So now let's see.

51
00:03:27,820 --> 00:03:30,490
Let's console.log this one or student.

52
00:03:30,490 --> 00:03:33,070
And now back to the terminal here.

53
00:03:33,460 --> 00:03:37,270
Let me clear the terminal and let me run the file again.

54
00:03:37,300 --> 00:03:38,710
Let's see what you're going to get.

55
00:03:38,710 --> 00:03:42,370
Well, I get the same thing as what cursor.

56
00:03:42,370 --> 00:03:44,970
So I need to use what is called array.

57
00:03:44,980 --> 00:03:50,890
So any time you are returning multiple command from MongoDB, unless you convert it to array.

58
00:03:50,890 --> 00:03:59,320
So here are going to be to array as that, save it and now back to the terminal and let's restart it

59
00:03:59,320 --> 00:04:00,250
again.

60
00:04:01,930 --> 00:04:05,230
Click the console and here we go.

61
00:04:05,230 --> 00:04:08,980
Let's see, you're going to have two documents and indeed we have it.

62
00:04:08,980 --> 00:04:12,460
The first one is this one and the second one is this.

63
00:04:12,460 --> 00:04:15,130
Dondo and Emmanuel are from Kumasi.

