1
00:00:00,300 --> 00:00:07,710
And once we have our scheme and model in place before we can start setting up any kind of functionality,

2
00:00:08,130 --> 00:00:09,450
of course we need to have data.

3
00:00:10,080 --> 00:00:16,890
Otherwise, how are you going to set up any kind of filtering if you have no product in a database?

4
00:00:17,280 --> 00:00:19,230
And effectively, we have two choices.

5
00:00:19,620 --> 00:00:28,440
You either can set up a postcard and then just manually add them, or a better approach is just to automate

6
00:00:28,440 --> 00:00:33,900
this and essentially just have some kind of list and pass it on to your database.

7
00:00:34,260 --> 00:00:40,710
Now, lucky for you, if you take a look at our project, you'll notice the product, Jason.

8
00:00:41,590 --> 00:00:48,350
And essentially, this is just a list of products just so we can start working on the filter functionality

9
00:00:48,760 --> 00:00:56,890
and the only thing we need to do is set up populated areas where we will dynamically add all of these

10
00:00:56,890 --> 00:00:58,770
values to our database.

11
00:00:59,050 --> 00:01:05,890
So instead of going the manual route where one by one we have them will right away just add them to

12
00:01:05,890 --> 00:01:09,990
our database by actually invoking the populate address.

13
00:01:10,420 --> 00:01:16,170
And the way it's going to look like we're going to go over here, will first grab our data entry.

14
00:01:16,450 --> 00:01:20,830
So let's say over here, dot envy, then we want to go with Canford.

15
00:01:21,220 --> 00:01:25,930
And then what's really interesting, that we need to have another connection.

16
00:01:26,170 --> 00:01:30,730
So, yes, we have one for objets, of course, that still stays the same.

17
00:01:30,730 --> 00:01:37,540
But since we want to connect to the database one more time, we'll have to grab that connect function

18
00:01:37,540 --> 00:01:38,170
as well.

19
00:01:38,680 --> 00:01:42,910
And here is going to go to connect the web.

20
00:01:43,060 --> 00:01:48,220
Of course, that is coming from where that is coming from our DB folder.

21
00:01:48,230 --> 00:01:48,630
Correct.

22
00:01:48,940 --> 00:01:53,740
So we go here with DB and then more specifically, connect, not the first thing we want to grab.

23
00:01:54,070 --> 00:01:57,100
Then we want to grab the model and you'll see why.

24
00:01:57,430 --> 00:02:00,450
And we just need to come up with a name and I'm going to go good product.

25
00:02:00,850 --> 00:02:08,259
And then of course, we are requiring that it is coming from the models and more specifically, product.

26
00:02:09,100 --> 00:02:15,070
And then lastly, I want those Jason products, because that's the data that I'm going to be passing

27
00:02:15,070 --> 00:02:16,060
on to the database.

28
00:02:16,450 --> 00:02:18,580
So here we need to come up with a name.

29
00:02:19,000 --> 00:02:24,630
In this case, I think I'm going to go get some products and we'll set it equal to require and where

30
00:02:24,670 --> 00:02:27,120
the file is actually sitting right next to us.

31
00:02:27,370 --> 00:02:32,700
So I'll just go with Forward Slash and then we're looking for product Gersen.

32
00:02:33,010 --> 00:02:39,190
And once we have all of this in place, we want to set up that start function one more time.

33
00:02:39,470 --> 00:02:42,460
Or in this case, of course, we're not going to be setting up that.

34
00:02:42,460 --> 00:02:50,350
Listen, we simply want to connect through the database and then use the model to automatically add

35
00:02:50,350 --> 00:02:55,690
those JSON products, the one that we have in file to our database.

36
00:02:56,050 --> 00:02:59,740
And the way it's going to look like we're going to go over here with Consed and start.

37
00:03:00,660 --> 00:03:07,160
And we'll set it equal to a sink in here, will set up another try catch so.

38
00:03:07,550 --> 00:03:11,840
So let's go try to catch and of course, eventually we'll invoke it here as well.

39
00:03:12,300 --> 00:03:15,630
And then I want to go with my white van.

40
00:03:15,640 --> 00:03:22,740
We want to pass in the corner, Debbie, and of course, inside of Debbie will pass in the process that

41
00:03:22,860 --> 00:03:25,160
the envy and of course, are variable.

42
00:03:25,170 --> 00:03:28,730
So mango and underscore you are right.

43
00:03:29,160 --> 00:03:35,780
And just because I want to see whether we're going to get some weird bugs, I'm also going to type in

44
00:03:35,790 --> 00:03:37,170
a catch a log.

45
00:03:38,070 --> 00:03:44,040
So go with Lugg and then we're going to be looking for the error and once we have all this in place,

46
00:03:44,310 --> 00:03:46,170
we can at least try the connection.

47
00:03:46,390 --> 00:03:48,300
Now, there's still some code that's missing.

48
00:03:49,080 --> 00:03:50,850
We'll get to it in another time.

49
00:03:51,130 --> 00:03:57,450
So, first of all, I want to do is stop the server over here and we just want to go.

50
00:03:57,690 --> 00:04:00,670
We have to start invoke it online.

51
00:04:00,700 --> 00:04:02,730
In this case, I'm not looking for an old man.

52
00:04:03,000 --> 00:04:04,980
I simply go with node.

53
00:04:05,220 --> 00:04:07,130
And then, of course, I'm looking for to find him.

54
00:04:07,500 --> 00:04:11,340
So since I'm already in a star, I just need to write populate.

55
00:04:11,790 --> 00:04:18,660
And then once we run it, if our connection again is successful, we shouldn't see any errors in a console.

56
00:04:19,050 --> 00:04:25,020
Now, if you want to help yourself out, of course, you can just type your log and let's just say success

57
00:04:25,020 --> 00:04:26,390
or something along those lines.

58
00:04:26,760 --> 00:04:31,350
So let's say here success and point.

59
00:04:31,560 --> 00:04:32,970
Let's say one more time again.

60
00:04:32,970 --> 00:04:33,720
Let's stop it.

61
00:04:33,990 --> 00:04:39,950
And if you remember from tutorial, in order to go back to the last command, we simply press arrow

62
00:04:39,960 --> 00:04:41,550
key up or down markers.

63
00:04:41,790 --> 00:04:43,940
We're going to press it down and check it out.

64
00:04:44,100 --> 00:04:48,880
Now, of course, we have success, so we successfully connected to the database.

65
00:04:48,900 --> 00:04:54,350
Now, if I want to check out the error or coming out of the data entry, stop the server one more time.

66
00:04:54,630 --> 00:04:57,240
Sorry about the detour, but these things are important.

67
00:04:57,480 --> 00:05:03,720
And then once we run out, of course, we're not successful connecting to the database because the you

68
00:05:03,720 --> 00:05:05,920
are our primer is not provided.

69
00:05:06,060 --> 00:05:06,510
Awesome.

70
00:05:06,600 --> 00:05:10,740
So let me comment on the data entry and clear everything.

71
00:05:11,040 --> 00:05:16,220
And once we have successfully connected to our database, there's two things that I want to do.

72
00:05:16,560 --> 00:05:24,150
First, I want to remove all the products that are currently there and then I want to use the create

73
00:05:24,420 --> 00:05:26,600
and just pass in the JSON product.

74
00:05:26,970 --> 00:05:33,270
So if you remember in a previous setup and I think I'm just going to go for final and let me look for

75
00:05:33,270 --> 00:05:39,210
controllers and tasks, notice here this create we passed here a object.

76
00:05:39,540 --> 00:05:41,760
Correct, when we were creating that task.

77
00:05:42,240 --> 00:05:45,640
Now what we can also do is pass in the array.

78
00:05:45,930 --> 00:05:53,220
So if you take a look at the product and I'm sorry this one products, Jason, you'll notice that this

79
00:05:53,220 --> 00:05:55,280
is an array at the end of the day.

80
00:05:55,680 --> 00:06:02,400
And since this is an array, what I can do, I can just pass this thing into the dot create.

81
00:06:02,730 --> 00:06:09,210
And by doing so, of course, I'll add all of these products to our database.

82
00:06:09,400 --> 00:06:10,290
So let's try it out.

83
00:06:10,680 --> 00:06:12,210
Let me navigate here.

84
00:06:12,210 --> 00:06:15,030
The populate one have the adjacent products.

85
00:06:15,370 --> 00:06:16,430
I'm in good shape.

86
00:06:16,650 --> 00:06:21,120
So now let me go below the weight board before the success.

87
00:06:21,540 --> 00:06:26,040
And in here I want to go with a weight now, not waiting for the actual response.

88
00:06:26,460 --> 00:06:33,590
And I want to go with my model because model has all those functions and then we want to go with delete

89
00:06:33,630 --> 00:06:34,050
many.

90
00:06:34,300 --> 00:06:37,530
So now I just want to remove all the products that are currently there.

91
00:06:37,800 --> 00:06:40,350
Of course, in our case there are no products.

92
00:06:41,100 --> 00:06:47,730
I'm just making sure that later, if you want to use it, then whatever gibberish you added or whatever

93
00:06:47,730 --> 00:06:51,950
data you currently have, you just remove it and then you start from scratch.

94
00:06:52,260 --> 00:06:53,640
This is technically optional.

95
00:06:53,760 --> 00:06:54,540
You don't want to do it.

96
00:06:54,750 --> 00:06:55,500
You don't have to.

97
00:06:55,500 --> 00:07:01,920
But my guess, I always like to start with scratch and the line we want to go with a wait and then product

98
00:07:02,580 --> 00:07:05,290
product and then I remember the function create.

99
00:07:05,610 --> 00:07:11,220
So now we're just dynamically creating a bunch of product by passing in adjacent products.

100
00:07:11,400 --> 00:07:14,520
So all we have to do here we go with Jason product.

101
00:07:15,340 --> 00:07:20,590
And now let's try it one more time and then, of course, we'll double check in our application zone

102
00:07:20,590 --> 00:07:26,680
here, going to go back to my console and then I want to go with Nold and populate.

103
00:07:26,890 --> 00:07:31,480
And if I see the success, then I know that I'm heading in the right direction.

104
00:07:31,720 --> 00:07:34,330
So now let me just go back to my Atlas one.

105
00:07:34,660 --> 00:07:35,890
Let me refresh.

106
00:07:36,220 --> 00:07:44,770
And now where I have my collections, I should have more values and effectively I have the story API.

107
00:07:44,830 --> 00:07:45,280
Awesome.

108
00:07:45,550 --> 00:07:50,600
And in here I have, of course, all the products and I'm not sure how many I set up.

109
00:07:50,770 --> 00:07:55,310
It really doesn't matter if you see these products added to your database.

110
00:07:55,540 --> 00:08:00,190
Now, of course, we can start finally setting up our filter functionality.

111
00:08:00,820 --> 00:08:06,980
And while we're still on topic, actually, no, there is a method by the name of it.

112
00:08:07,480 --> 00:08:10,060
Now, why that would be useful in our case because.

113
00:08:10,060 --> 00:08:11,380
Well, let's think about it.

114
00:08:11,860 --> 00:08:13,780
So we have our popular address.

115
00:08:14,200 --> 00:08:19,720
If we're successful, then we might as well just terminate the whole process, correct?

116
00:08:19,980 --> 00:08:22,780
I mean, we don't need this file to be running.

117
00:08:23,320 --> 00:08:26,140
And if there is an error, then again, we'll exit.

118
00:08:26,380 --> 00:08:28,630
But maybe we error code.

119
00:08:29,020 --> 00:08:34,840
And the way we set up the process that exit is simply by navigating through the start here.

120
00:08:35,110 --> 00:08:42,789
And then probably right after the success, we'll set up a process then that is that global variable

121
00:08:42,789 --> 00:08:43,809
that we have access to.

122
00:08:44,070 --> 00:08:47,100
Then we go with exit and that's the method name.

123
00:08:47,290 --> 00:08:54,520
And that if we pass in zero, that just means that everything went well and we just exiting the process.

124
00:08:54,840 --> 00:09:01,150
However, if I take the exit method and pass it in and of course in this case, since I'm running it

125
00:09:01,150 --> 00:09:07,920
in the cache, I want to pass in error code, I'll pass in one and then let's do it one more time.

126
00:09:07,930 --> 00:09:11,170
I'll clear everything and I'll not start out with an error.

127
00:09:11,410 --> 00:09:14,620
But let's just go here with node populate.

128
00:09:14,860 --> 00:09:20,460
And now you'll notice that once we're successful, we actually exit the process.

129
00:09:20,470 --> 00:09:20,750
Why?

130
00:09:20,750 --> 00:09:22,930
Well, because we have process, not exit.

131
00:09:23,100 --> 00:09:26,470
And of course, the code in this case that we passed in is zero.

132
00:09:26,630 --> 00:09:32,980
And if you want to double check your data, just navigate back to the atlas and you'll see that all

133
00:09:32,980 --> 00:09:35,770
your product data is still there.

