1
00:00:00,500 --> 00:00:06,840
Once we have dynamically added products to our database, I think I can just close the popular address,

2
00:00:07,470 --> 00:00:12,990
at least in my case I'm not going to use the more the same goes for product jurors and the rest of the

3
00:00:12,990 --> 00:00:16,920
work will pretty much do over here in the controllers.

4
00:00:17,400 --> 00:00:23,850
And the first thing that I want to showcase, truly, this is a refresher where essentially if we want

5
00:00:23,850 --> 00:00:29,610
to search for a product in a mongoose, meaning for some kind of items in our case, of course, that

6
00:00:29,610 --> 00:00:30,150
is product.

7
00:00:30,540 --> 00:00:32,880
Well, we need to go with fine method.

8
00:00:32,880 --> 00:00:33,270
Correct.

9
00:00:33,570 --> 00:00:34,770
So let's just go here.

10
00:00:35,580 --> 00:00:41,640
I'm in the Mongoose Docs and I'm looking forward to queries and I don't keep on scrolling.

11
00:00:41,640 --> 00:00:42,420
Keep on scrolling.

12
00:00:42,630 --> 00:00:49,450
In this case, they show the find one example, but the idea effectively is the same, that if you go

13
00:00:49,450 --> 00:00:56,120
with find and of course if you pass in the empty object, then you'll get all the documents.

14
00:00:56,490 --> 00:01:00,210
And of course in the object you can also pass in some options.

15
00:01:00,600 --> 00:01:05,910
And if you go with property, then you just need to provide what value you are looking for.

16
00:01:06,180 --> 00:01:13,260
So in our case, if we take a look at our model or here in the project, well, these are our properties,

17
00:01:13,260 --> 00:01:13,650
correct?

18
00:01:13,890 --> 00:01:17,520
Whether that's name price feature and yada, yada, yada.

19
00:01:17,790 --> 00:01:25,260
So in here, let me start my server and then back in Product Gess, I want to get the model because

20
00:01:25,260 --> 00:01:31,740
of course we'll go over the basics first where I'll start by just getting the product and that is equal

21
00:01:31,740 --> 00:01:32,700
to require.

22
00:01:33,420 --> 00:01:35,310
And I'm looking for my model again.

23
00:01:35,820 --> 00:01:43,110
So I'll go two levels up and then I'm looking for the models and then the product and then let's start

24
00:01:43,110 --> 00:01:44,120
in a static one.

25
00:01:44,550 --> 00:01:46,230
So I'll do a little bit of work here.

26
00:01:46,440 --> 00:01:52,830
I'll show you the manual approach and then you can get all product while this is where all set of the

27
00:01:52,830 --> 00:01:57,030
real functionality, the one that we'll use in our project.

28
00:01:57,270 --> 00:01:59,780
And then we already know the action car.

29
00:01:59,850 --> 00:02:00,690
So that's good.

30
00:02:00,990 --> 00:02:05,130
And I'll just start by saying const product and simple.

31
00:02:05,160 --> 00:02:05,880
Let's take a look.

32
00:02:05,880 --> 00:02:11,730
If we pass in the empty object in here, let's go with a wait and learn product.

33
00:02:11,730 --> 00:02:17,640
That's the name of the model and then find and like I said, let's just pass in the empty object.

34
00:02:17,880 --> 00:02:23,910
And then instead of the message, I'm just going to go here with product and then let's test that out

35
00:02:24,180 --> 00:02:25,130
in the postman.

36
00:02:25,410 --> 00:02:27,270
So I'll go back to my testing one.

37
00:02:27,420 --> 00:02:32,500
I'll send it and I should see my array of products.

38
00:02:33,050 --> 00:02:36,710
If that is the case, then of course we're heading in the right direction.

39
00:02:36,990 --> 00:02:44,610
Now, if I want to be more specific, if I want to say, hey, get me the product where the company

40
00:02:44,610 --> 00:02:52,500
is equal to this one or get me the product where name is equal to this one, or maybe get me only the

41
00:02:52,500 --> 00:02:58,350
featured one, then of course, we simply need to go back here and where we have the object, well,

42
00:02:58,350 --> 00:03:04,780
I can say featured Richard, and this is going to be equal to what, true or false?

43
00:03:05,160 --> 00:03:08,760
So let's just pass intro and then let's run it one more time.

44
00:03:09,030 --> 00:03:15,570
And what you'll notice in your static world, only the products that are featured are going to be displayed.

45
00:03:15,900 --> 00:03:16,620
And you're not.

46
00:03:16,620 --> 00:03:21,810
I think in this case, it is going to be very helpful if I'm just going to go with those number of hits.

47
00:03:22,730 --> 00:03:28,940
And I'll set it equal to my right, because that way you can ride or see if you're getting the correct

48
00:03:28,940 --> 00:03:29,990
set of data.

49
00:03:30,300 --> 00:03:31,130
So let's go here.

50
00:03:31,470 --> 00:03:33,560
And in this case, it says something went wrong.

51
00:03:33,830 --> 00:03:38,780
And of course, because for some reason I decided to add a number of hits in the form.

52
00:03:38,870 --> 00:03:44,550
And this is actually something that I'll cover later why we get those errors and how to avoid them.

53
00:03:44,570 --> 00:03:45,710
So let me remove it.

54
00:03:46,010 --> 00:03:47,650
This was pretty much an early test.

55
00:03:47,930 --> 00:03:49,560
What kind of errors we're going to have.

56
00:03:49,760 --> 00:03:53,150
So let me run it over here where I have the JSON response.

57
00:03:53,420 --> 00:03:57,980
So don't be like me, be better than me and don't pass it into the final pass.

58
00:03:58,010 --> 00:04:02,450
And actually where you are sending the response and let's go back over here.

59
00:04:02,640 --> 00:04:08,780
Let's send and of course, I have the product and all the way at the bottom half number of hits is equal

60
00:04:08,780 --> 00:04:09,220
to seven.

61
00:04:09,590 --> 00:04:13,910
And if you'll take a look, you'll see that all the products have featured.

62
00:04:14,240 --> 00:04:14,570
True.

63
00:04:14,870 --> 00:04:20,450
And you can probably already imagine that if I'm just going to go here with name and of course, we

64
00:04:20,450 --> 00:04:21,170
can combine them.

65
00:04:21,440 --> 00:04:25,910
And again, this is something that we'll cover in more detail in the next video.

66
00:04:25,910 --> 00:04:29,030
So therefore, our moment and I'll just start with scratch.

67
00:04:29,030 --> 00:04:32,140
I'll say name is equal to whatever I have here.

68
00:04:32,600 --> 00:04:33,380
My apologies.

69
00:04:33,380 --> 00:04:39,470
I copied the wrong thing if I have multiple tables and for some reason I just want to look for this

70
00:04:39,470 --> 00:04:39,740
one.

71
00:04:40,040 --> 00:04:44,660
I can just pass in the value where I say, yeah, get me the product.

72
00:04:44,930 --> 00:04:47,990
But the name property needs to have this value.

73
00:04:48,170 --> 00:04:51,920
And now, of course, once we send, I should get only one.

74
00:04:52,480 --> 00:04:55,470
That's the only one that has the matching name.

75
00:04:55,610 --> 00:04:57,790
Hopefully we're clear on a basic setup.

76
00:04:58,100 --> 00:05:05,150
So now of course, we can start implementing the get all products where the setup is going to be more

77
00:05:05,150 --> 00:05:11,000
complex than just hard coding the name or any of the other property values.

