WEBVTT

00:03.970 --> 00:08.560
Hey, did everyone that they shared and in this video we'll be writing model for our product itself

00:08.560 --> 00:10.390
and feel free to add more products.

00:10.390 --> 00:14.380
Now you have full experience of how to handle that, so it shouldn't be a big deal.

00:14.560 --> 00:19.180
Now, this one is going to be a little bit of a longer video because we have so much of things to add

00:19.180 --> 00:22.900
into the into the model of the product itself.

00:22.900 --> 00:24.730
So it's going to take a little bit while.

00:24.730 --> 00:26.410
So have patience on that part.

00:26.590 --> 00:28.540
First, let's go ahead and set up our model.

00:28.540 --> 00:29.470
We have already written that.

00:29.470 --> 00:30.640
So it's inside the product.

00:30.870 --> 00:32.620
So how do we write our model itself?

00:32.620 --> 00:34.600
It's fairly, fairly simple.

00:34.840 --> 00:40.150
So let's go ahead and say, Hey, Mongoose, please help me to write a model.

00:40.150 --> 00:45.060
And it's going to help you by saying require mongoose.

00:45.670 --> 00:48.430
Okay, so we use a simple method from the mongoose itself.

00:48.430 --> 00:53.560
First, let's hold that into a variable and let's call this one as product schema.

00:54.400 --> 00:55.030
Schema.

00:55.030 --> 00:55.780
There we go.

00:55.870 --> 01:00.910
And the method from the mongoose itself is going to say, Hey, just help him to create a schema.

01:00.910 --> 01:04.300
So I need to say new because it's a class here.

01:04.300 --> 01:07.840
So new mongoose dot schema.

01:07.840 --> 01:08.410
There we go.

01:08.410 --> 01:12.550
And inside that we play some a whole lot of objects, whatever we actually need up there.

01:12.790 --> 01:18.490
But first, I always love to export this one, so I'm going to go ahead and save module exports so anybody

01:18.490 --> 01:19.660
can import that.

01:19.660 --> 01:22.600
And we're going to say, Hey, Mongoose, help me to create a model.

01:22.600 --> 01:26.020
So Mongoose model model takes to parameter that.

01:26.020 --> 01:27.400
What do you want to call to a model?

01:27.400 --> 01:31.270
And just with the convention, we always call with the uppercase letter, but I know that inside the

01:31.270 --> 01:33.730
DB it will go as products all lowercase.

01:33.940 --> 01:35.440
What schema do you want to use?

01:35.440 --> 01:37.810
I want to use a schema of product schema.

01:37.810 --> 01:38.500
There we go.

01:39.050 --> 01:39.220
Okay.

01:39.520 --> 01:42.010
So this is the most basics that we got up here.

01:42.010 --> 01:46.030
Now we need to actually bring some data and we'll be bringing data from here itself.

01:46.060 --> 01:49.120
So I'll be just copying everything from here.

01:49.120 --> 01:52.600
It will help me to actually get easy check up here.

01:53.050 --> 01:58.840
I'll come here and add this and obviously I'll remove this, all of that in a minute.

01:58.840 --> 02:01.570
But first, I'm going to go ahead and comment this out.

02:02.020 --> 02:02.530
Okay.

02:02.530 --> 02:05.620
So let's go ahead and add all of the data one by one.

02:05.620 --> 02:07.780
So let's go ahead and do that first.

02:07.780 --> 02:08.920
Let's start with the name.

02:08.920 --> 02:10.510
So we're going to go ahead and say name.

02:10.510 --> 02:13.870
I can of course, say string directly here, but I have a lot more to handle.

02:13.870 --> 02:17.290
So that's why I'm going to say define properties one by one.

02:17.290 --> 02:21.130
So first one is it's going to be of type string, nice and easy.

02:21.130 --> 02:23.590
Now the name obviously is going to be required fields.

02:23.590 --> 02:28.450
So we're going to go ahead required and not only just true we'll pass on an array through is the first

02:28.450 --> 02:33.490
property or zeroth property in this case and we're going to provide the error message as well.

02:33.490 --> 02:41.860
So please provide product, product name.

02:42.970 --> 02:43.180
Okay.

02:43.270 --> 02:44.770
So error message is also handled.

02:44.770 --> 02:47.290
We are also going to use a property, another one trim.

02:47.290 --> 02:49.600
I'm pretty sure most of you have heard about this property.

02:49.600 --> 02:52.020
It's really an easy property to work on with.

02:52.060 --> 02:57.070
If you have any additional spaces at the end of your product name, you can go ahead and remove that.

02:57.070 --> 02:59.950
You can actually use this property inside the email as well.

03:00.100 --> 03:02.050
Just a cautionary stuff.

03:02.410 --> 03:06.820
Now you can also go ahead and define what kind of maximum length you want to support in this case.

03:06.820 --> 03:12.670
So I'm going to assume that probably 120 words is characters is not words.

03:12.670 --> 03:15.610
120 characters is more than enough for a product name.

03:15.940 --> 03:18.280
Let's give a provide a message to the user as well.

03:18.520 --> 03:28.180
That product name should not be more than 120 characters.

03:28.180 --> 03:29.020
So there we go.

03:29.290 --> 03:33.490
Okay, let's go ahead and do a copy of this so that it helps us a little bit.

03:33.490 --> 03:37.390
First, put a comma and now let's go ahead and make a copy of this.

03:38.050 --> 03:38.290
Okay.

03:38.380 --> 03:40.870
So next one that we have is the pricing.

03:40.870 --> 03:43.870
So let's go ahead and say I want to give you a price here.

03:44.140 --> 03:47.200
Now, the price is obviously not going to be a string.

03:47.200 --> 03:50.080
It's rather going to be a number required.

03:50.080 --> 03:50.560
True.

03:50.590 --> 03:53.590
We are going to say please provide product price.

03:53.710 --> 03:54.640
Nice error message.

03:54.640 --> 03:56.560
They're very consistent trim.

03:56.560 --> 03:58.000
We don't need to do a trim.

03:58.270 --> 04:04.600
We're going to go ahead and remove this maxlength surely I can go ahead and say, hey, maxlength is

04:04.600 --> 04:09.640
going to be, let's just say five now these are digits since we are talking in the case of numbers.

04:09.640 --> 04:10.750
So these are the digits.

04:10.750 --> 04:13.300
I don't want any product to be more than five digits.

04:13.300 --> 04:19.330
Surely I would love to sell a t shirt of probably five lakh rupees or 20 lakh rupees, but I think five

04:19.330 --> 04:21.280
digit is good enough.

04:21.280 --> 04:26.560
So product price should not be more than.

04:28.810 --> 04:29.800
Five digits.

04:29.800 --> 04:32.200
And again, these are not digits counting from the zero.

04:32.200 --> 04:37.330
So five digit, I guess it's more than if you can go ahead and change this probably to six.

04:37.330 --> 04:39.040
Maybe you want to sell expensive one.

04:39.040 --> 04:40.930
You get the idea how this is being done.

04:41.770 --> 04:42.250
Okay.

04:42.340 --> 04:44.080
Next up is the description.

04:44.080 --> 04:45.970
So let's go ahead and add this one.

04:46.930 --> 04:47.350
Okay.

04:47.740 --> 04:51.010
Now let's go ahead and change this one to this.

04:52.700 --> 04:53.660
Corruption.

04:55.530 --> 04:56.310
Description.

04:56.310 --> 04:57.000
There we go.

04:57.260 --> 04:57.570
Okay.

04:57.570 --> 04:59.910
So this one is going to be of type string.

05:00.450 --> 05:05.520
And in the description, we are going to not put a maximum length because description can be long and

05:05.520 --> 05:08.040
maybe there are future plans of supporting more stuff.

05:08.040 --> 05:11.720
But we're going to say required because this is kind of important.

05:11.730 --> 05:15.060
Otherwise our application will look weird if this will be optional.

05:15.150 --> 05:19.650
So we're going to say please provide product description.

05:20.400 --> 05:22.740
Next one is a photos.

05:22.740 --> 05:24.840
So let's go ahead and work on with the photos.

05:24.840 --> 05:32.190
So let's go ahead and copy this, paste that OC The photos is going to be an interesting one.

05:32.190 --> 05:36.180
Not really interesting because something like this, we have already handled that.

05:36.180 --> 05:37.860
So shouldn't be a big deal there.

05:38.550 --> 05:44.520
Let's go ahead and call this one as photos now this time at the at the model that we have previously

05:44.520 --> 05:49.620
worked the user itself, this is just a photo because we were adding just one photo in this case, this

05:49.620 --> 05:53.400
is going to be a photos because we are adding a whole lot more there.

05:53.400 --> 05:56.910
So this time it's not going to be an object directly.

05:56.910 --> 06:00.360
It's rather going to be an array so that somebody can actually loop through it.

06:00.360 --> 06:03.960
And these are all the things you have to take care of while designing a model itself.

06:03.960 --> 06:07.170
And inside this we're going to add an object.

06:07.170 --> 06:12.000
Each individual object will have two properties ID and the security URL.

06:12.000 --> 06:14.040
So something like we have already worked with that.

06:14.040 --> 06:20.640
So ID again, we are going to go ahead and say, hey, this one is going to be of type.

06:20.640 --> 06:21.420
There we go.

06:21.750 --> 06:26.220
Type of the ID is going to be string and this one is going to be required.

06:26.220 --> 06:29.340
So yes, we need images up there.

06:29.670 --> 06:31.740
So we are going to say required.

06:31.740 --> 06:37.620
So at least somebody passes us one image and that one image is going should have an ID and should have

06:37.620 --> 06:39.990
a security model as well.

06:40.170 --> 06:42.120
So required is going to be.

06:42.630 --> 06:43.350
Come on.

06:43.650 --> 06:45.360
Required is going to be true.

06:46.650 --> 06:54.750
And now we can put up a comma and make a copy of this one, and we're going to call this one as a secure

06:54.930 --> 06:58.410
URL type a string required is true.

06:58.440 --> 06:59.580
We don't need this trailing.

06:59.580 --> 07:00.420
And there we go.

07:00.450 --> 07:06.690
Now we can have as many objects inside this ETA, but each object should carry these two properties.

07:06.690 --> 07:09.060
So this is how we are going to handle the photos.

07:09.600 --> 07:11.190
Okay, so this is all good.

07:11.190 --> 07:18.540
Now, coming up after the photos, I need to copy this one just to save some minutes, some seconds.

07:18.720 --> 07:19.470
There we go.

07:20.010 --> 07:22.620
So after the photos, we got into the categories.

07:22.620 --> 07:24.000
Now, this is interesting one.

07:24.000 --> 07:28.830
Now surely I could have created another model just for the categories, but since in the discussion

07:28.830 --> 07:33.720
we came to know that it's short sleeves, long sleeves, sweatshirts and the hoodies as well.

07:33.720 --> 07:35.940
So that's why we are super easy on that part.

07:35.940 --> 07:41.460
But once you know how to inject users into the product itself, I'm pretty sure it shouldn't be a tough

07:41.460 --> 07:44.220
to add categories into the product because they are just models.

07:44.220 --> 07:47.190
Once you know how to inject one model, you can add other models as well.

07:47.430 --> 07:52.230
So let's go ahead and call this one as category, not categories.

07:52.260 --> 07:54.180
It is kind of a makes sense.

07:54.540 --> 07:56.460
Okay, this is going to be a type string.

07:56.460 --> 07:58.680
And again, did we made a mistake in the string?

07:58.680 --> 08:00.090
Yep, we made a mistake.

08:01.080 --> 08:01.860
There we go.

08:01.860 --> 08:03.960
So a small typo there just fixed it.

08:04.470 --> 08:05.700
And this one also.

08:06.120 --> 08:11.610
Okay, so categories is going to be type string and we are going to say true and we are going to provide

08:11.610 --> 08:12.210
a message.

08:12.210 --> 08:12.930
Please.

08:14.410 --> 08:17.470
Select categories.

08:18.920 --> 08:20.330
Category from.

08:22.160 --> 08:28.220
We are going to go ahead and save from and let's say Daesh and this one is going to be only short.

08:30.160 --> 08:32.530
Dash sleeves.

08:34.730 --> 08:40.490
And we're going to say long dash sleeves or it can be.

08:41.890 --> 08:44.890
Sweat does shirt.

08:46.410 --> 08:47.760
Or it can be hoodies.

08:47.760 --> 08:49.600
So we're going to go ahead and say hoodies.

08:49.620 --> 08:54.780
Now we are why we are providing message like this, because we'll be providing the option to select

08:54.780 --> 08:55.230
here.

08:55.260 --> 08:59.880
Now, in case you want to any time restrict the users option in is always your best friend.

08:59.880 --> 09:04.140
So we're going to say, hey, we're going to provide an enum and inside this enum we are going to go

09:04.140 --> 09:05.580
ahead and provide the values.

09:05.580 --> 09:06.450
So there we go.

09:06.750 --> 09:10.470
Values is always an error in the enum, so let's go ahead and provide these.

09:10.470 --> 09:15.600
So we're going to go ahead and say, hey, this one you can choose from short dash sleeves.

09:16.440 --> 09:19.470
And again, you have to provide the exact name that you are mentioning here.

09:19.470 --> 09:22.710
Make sure it is not case and not uppercase lowercase.

09:22.710 --> 09:24.120
Make sure you are consistent there.

09:24.780 --> 09:27.420
Long dash sleeves.

09:28.440 --> 09:29.490
We are going to go ahead.

09:29.490 --> 09:33.900
Another one which is going to be sweat again in the codes.

09:36.340 --> 09:37.360
Come on.

09:37.690 --> 09:39.700
Sweat shirt.

09:40.730 --> 09:42.440
If I can write that finally.

09:42.920 --> 09:44.900
And the final one is hoodies.

09:45.650 --> 09:49.580
Now, it makes sense in this case, since we have only these ones, in case you want to give the user

09:49.580 --> 09:53.300
ability to just kind of a CRUD functionality with the categories as well.

09:53.300 --> 09:55.160
We have already done that in the main course.

09:55.160 --> 09:57.220
You might want to check that out, but I don't think so.

09:57.230 --> 09:59.390
It should it be a big deal for you now?

09:59.870 --> 10:02.810
Okay, so this is all good and it looks great.

10:02.810 --> 10:10.550
And by the way, you can also provide a message and in case somebody provides a category which is something

10:10.550 --> 10:14.830
else than this, then specifically you can go ahead and provide a message for that.

10:14.840 --> 10:19.940
Now this message required is going to come in whenever somebody says that I'm not providing you any

10:19.940 --> 10:24.410
category, but if somebody chooses something else, then we can go ahead and provide a message here.

10:24.410 --> 10:26.450
So the property is known as message.

10:26.450 --> 10:27.140
There we go.

10:27.320 --> 10:30.890
And the message goes just like in the codes that please.

10:33.100 --> 10:34.610
We can actually copy this.

10:34.630 --> 10:35.890
That would be easier.

10:36.340 --> 10:43.600
We're going to go ahead and say please select category only from short sleeves.

10:44.260 --> 10:44.860
There we go.

10:44.860 --> 10:47.380
From short sleeves, long sleeves, sweatshirt.

10:49.520 --> 10:50.450
And howdy.

10:50.480 --> 10:51.410
So there we go.

10:51.590 --> 10:57.050
So now this is really easy and gave us a chance to explore it a little bit more about how to explode

10:57.080 --> 10:57.770
enemies.

10:58.110 --> 10:59.420
Okay, so category is all done.

10:59.500 --> 11:01.220
Now let's go ahead and work on with the brand.

11:01.250 --> 11:04.400
So after the category, let's go ahead and add a brand.

11:05.390 --> 11:07.570
So brand is going to be really simple.

11:07.580 --> 11:09.530
Let's go ahead and work on like that.

11:09.530 --> 11:11.520
And in the brand we're going to say type.

11:11.540 --> 11:13.970
The idea behind the brand is really simple right now.

11:13.970 --> 11:19.610
It's just learn code online, but maybe tomorrow I want to sell t shirts of Adidas or maybe something

11:19.610 --> 11:21.170
else, some cocreator on YouTube.

11:21.170 --> 11:23.180
So that's why we are adding a brand here as well.

11:23.420 --> 11:27.560
The required is going to be same, just like we have talked probably many times.

11:27.920 --> 11:28.520
True.

11:28.520 --> 11:34.730
And we're going to say please add a brand for clothing.

11:36.950 --> 11:37.970
What else we got?

11:38.330 --> 11:39.770
We got rating here as well.

11:39.770 --> 11:42.410
Now, this rating is interesting ratings.

11:42.410 --> 11:44.330
So let's go ahead and add this one.

11:45.900 --> 11:47.340
So there we go.

11:47.370 --> 11:48.260
Really simple.

11:48.270 --> 11:51.450
We don't need too much explanation on ratings.

11:51.480 --> 11:55.320
It's going to be of type number so that later on I can average it out.

11:55.320 --> 11:57.570
I can find a lot more stuff.

11:57.690 --> 12:01.680
And this is not going to be required because user will not pass on this one.

12:01.680 --> 12:06.300
We need to just provide a default because every single product will obviously have some of the ratings,

12:06.300 --> 12:11.760
but by default everything is off is going to start with a zero rating as the user will give on more

12:11.760 --> 12:12.150
ratings.

12:12.150 --> 12:13.680
Five star to start, three star.

12:13.680 --> 12:16.050
I'll add on an average into this rating.

12:16.050 --> 12:17.010
So I have to do that.

12:17.010 --> 12:19.440
I'll manually work on these things.

12:19.530 --> 12:20.280
Let's move on.

12:20.280 --> 12:21.270
What else we got?

12:21.390 --> 12:22.110
We got ratings.

12:22.110 --> 12:24.000
We got a number of reviews as well.

12:24.000 --> 12:25.200
So a number of reviews.

12:25.200 --> 12:25.890
Really simple.

12:25.920 --> 12:27.600
How many people have actually reviewed it?

12:27.600 --> 12:30.750
As soon as a new rating comes in, I'll just add one to this one.

12:30.750 --> 12:31.650
So really simple.

12:31.800 --> 12:38.070
We're going to go ahead and say number of reviews and that's going to be like this.

12:38.340 --> 12:45.450
This is going to be a type of number and obviously by default, there is going to be no rating.

12:45.450 --> 12:48.990
So the default says zero.

12:49.890 --> 12:50.610
Okay.

12:51.240 --> 12:53.370
Just a few more then this reviews.

12:53.370 --> 12:54.900
Now, this is an interesting one.

12:54.900 --> 12:58.800
We already got a discussion on this one, but we'll have a talk, small talk here as well.

12:59.010 --> 13:00.480
Let's go ahead and copy this.

13:00.480 --> 13:02.160
Put up in this guy.

13:02.580 --> 13:02.940
Okay.

13:02.940 --> 13:03.780
So what is this?

13:03.780 --> 13:05.550
This is actually reviews.

13:05.550 --> 13:09.420
So all the reviews, every single product is going to get a reviews.

13:09.420 --> 13:12.990
So whenever you add a review, it is associated with the product itself.

13:12.990 --> 13:14.970
That's why we are keeping it in the model itself.

13:14.970 --> 13:20.160
Now surely you can keep it into separate model and add an injection or something like this, but we

13:20.160 --> 13:20.940
won't be doing that.

13:20.940 --> 13:22.650
We'll be just keeping it as reviews.

13:22.710 --> 13:27.990
Now obviously this reviews is going to be array because maybe there are so many errors somebody wants

13:27.990 --> 13:28.950
to iterate through with it.

13:28.950 --> 13:30.150
So that is obvious.

13:30.180 --> 13:32.520
Now what do you want to inject into this one?

13:32.520 --> 13:36.870
The first thing that I would like to add is who is the user who has given me the ratings?

13:36.870 --> 13:39.060
Only logged in user can give me the rating.

13:39.270 --> 13:42.990
So how we inject this one, this is really, really simple.

13:42.990 --> 13:44.460
Like ridiculously simple.

13:44.580 --> 13:49.350
All you got to do is simply use Mongoose again after the column, of course.

13:49.350 --> 13:59.070
So I'll go to say is Mongoose dot schema and then just go ahead and say object id make sure this is

13:59.070 --> 14:00.240
exactly looks like this.

14:00.240 --> 14:01.650
Oh capital and I capital.

14:01.650 --> 14:04.680
So what I'm saying here is let me walk you through inside this.

14:04.680 --> 14:10.230
You have noticed that every single object that you add inside the database, it has this object.

14:10.230 --> 14:14.490
ID remember it is written as o capital and a capital so object ID.

14:14.490 --> 14:19.800
So what I'm saying is I will give you this object ID now in the object ID when you actually add them.

14:19.800 --> 14:24.930
It looks like just a long string with numbers and some letters, but it's actually a based on field

14:24.930 --> 14:27.120
just like JSON but based on field.

14:27.120 --> 14:28.860
Now this field has all of this numbers.

14:28.860 --> 14:33.150
So what I'm saying is whenever I'll be creating this, I'll inject this entire value up here.

14:33.150 --> 14:34.410
That's why I'm referencing it.

14:34.410 --> 14:38.820
That that there will be an object ID, mongoose, object ID that will come to you.

14:38.850 --> 14:41.250
You also have to pass on that.

14:41.250 --> 14:43.110
Hey, anything can be an object ID.

14:43.140 --> 14:46.590
Maybe it can come up from user, it can come up from product itself.

14:46.590 --> 14:48.450
Maybe you are creating categories from itself.

14:48.450 --> 14:52.710
So from where it should be coming up so that I can go ahead and validate it myself.

14:52.710 --> 14:57.180
So then you have to go ahead and provide a ref here, which is a reference that I'm going to go ahead

14:57.180 --> 14:58.290
and say user.

14:58.770 --> 15:03.570
Now this user needs to be exactly same as what you are calling it up here.

15:03.810 --> 15:05.400
Let me show you at the end of it.

15:05.400 --> 15:07.170
So this is what I'm calling it.

15:07.170 --> 15:09.420
I need to pass on exactly that in the reference.

15:09.420 --> 15:13.410
If you're calling it as category or whatever you are calling in, you just have to do this.

15:13.410 --> 15:15.390
Now, this two line of code, that's it.

15:15.390 --> 15:18.810
That's how you can inject another document value into other document.

15:18.810 --> 15:19.860
That's all it takes.

15:20.250 --> 15:25.050
Now we're going to go ahead and say this is a required field, so we're going to go ahead and say required

15:25.050 --> 15:26.070
a is true.

15:26.250 --> 15:31.170
So now any time a review comes in, they have to give me this user object.

15:31.710 --> 15:36.150
Now further down the road, we probably also would like to add a name of this.

15:36.150 --> 15:39.060
It will look good at the time of showing the review.

15:39.060 --> 15:42.060
So let's go ahead and say, hey, I need to provide a type.

15:42.240 --> 15:49.500
The type is going to be a string scroll a little bit and let's go ahead and move on to required.

15:51.130 --> 15:51.570
Okay.

15:51.580 --> 15:52.600
Now you can see it.

15:53.350 --> 15:59.950
Now you're going to see that this is a type and required is going to be true.

16:02.170 --> 16:02.650
Okay.

16:02.650 --> 16:03.970
So these are the basic field.

16:04.000 --> 16:08.380
Of course, whenever you are taking a rating, you need to take the rating a number between one and

16:08.380 --> 16:08.950
five.

16:08.950 --> 16:10.810
You can provide an enum here as well.

16:10.810 --> 16:12.820
That would be awesome, but I don't think so.

16:12.820 --> 16:16.270
It is required again, but surely having that is not a bad idea at all.

16:16.270 --> 16:18.700
And a comment that what do you want to say in the rating itself?

16:18.700 --> 16:19.630
So really simple.

16:19.720 --> 16:22.870
So we're going to go ahead and say, hey, this is the rating that you are providing.

16:22.870 --> 16:24.910
This rating will be of type number.

16:24.910 --> 16:30.880
Not like that, of course, like this type number.

16:31.030 --> 16:32.290
Come on.

16:32.560 --> 16:33.760
There we go.

16:33.940 --> 16:34.180
Okay.

16:34.210 --> 16:35.860
So this is going to be a type of number.

16:35.860 --> 16:37.480
Surely this is also required field.

16:37.480 --> 16:42.040
So what I'll do is I'll copy this and I'll paste it up here.

16:43.210 --> 16:44.560
Okay, so this is all done.

16:44.560 --> 16:46.420
Now, next thing is the comment itself.

16:46.420 --> 16:50.020
So let's go ahead and add a comma and give itself a copy.

16:50.320 --> 16:51.100
There we go.

16:52.610 --> 16:58.130
So this one is going to be a feedback, comment, whatever you want to call that, it's up to you.

16:58.310 --> 16:59.840
This is going to be a string.

16:59.840 --> 17:01.080
So all these fields.

17:01.100 --> 17:05.090
So now my review itself, or reviews rather itself is an array.

17:05.090 --> 17:10.250
And whenever you want to add any value into this array, you have to provide me for things.

17:10.250 --> 17:17.000
User and again users object ID, so you need to grab this somehow and then we have to provide the name

17:17.000 --> 17:18.080
rating and the common.

17:18.080 --> 17:22.970
And again grabbing the user ID shouldn't be a problem at all because only logged in user can give rating.

17:22.970 --> 17:25.910
So we have injected an object request dot user.

17:25.910 --> 17:27.980
So we'll be able to grab name and everything from there.

17:27.980 --> 17:29.450
So shouldn't be a big deal at all.

17:29.870 --> 17:30.140
Okay.

17:30.170 --> 17:32.090
Moving on now.

17:32.090 --> 17:33.230
The next thing is user.

17:33.230 --> 17:35.660
So what is the meaning of this user itself?

17:35.660 --> 17:37.520
So let me go ahead and shrink this review.

17:37.520 --> 17:38.420
It's too big.

17:38.840 --> 17:39.320
Okay.

17:40.010 --> 17:46.550
Now, the idea behind this user is because we might be having so many roles and user at the later point

17:46.550 --> 17:46.910
of time.

17:46.910 --> 17:52.100
Maybe you have a dedicated manager who adds product into your shop, so you want to see who has added

17:52.100 --> 17:52.850
this new product.

17:52.850 --> 17:55.640
So you might want to somebody who is accountable for that.

17:55.640 --> 17:58.700
And that is the only reason why we are adding this user field.

17:58.700 --> 17:59.780
So it's a great revision.

17:59.780 --> 18:03.260
Again, I want to see who is the logged in user who has created this project.

18:03.260 --> 18:05.590
So all I got to do is simply same.

18:05.600 --> 18:07.430
It's going to come up from another document.

18:07.430 --> 18:15.230
So we have to say this is going to be coming from mongoose dot schema, dot object id make sure the

18:15.230 --> 18:16.490
case sensitivity is there.

18:16.490 --> 18:20.330
I also need to provide a ref that hey from where I should reference this one.

18:20.330 --> 18:21.680
So in this case that's the user.

18:21.680 --> 18:22.490
So that's it.

18:22.610 --> 18:24.260
Now again, this is going to be required.

18:24.260 --> 18:27.590
Field So let's go ahead and say, hey, required is going to be true.

18:27.590 --> 18:31.520
I really want to know who has actually came in and added the field.

18:32.000 --> 18:33.650
Okay, what else is remaining?

18:33.650 --> 18:34.220
Just one.

18:34.220 --> 18:35.390
Come on, just one.

18:35.390 --> 18:36.170
We can do it.

18:36.260 --> 18:38.180
This one is going to be created at.

18:38.980 --> 18:40.630
And this one is going to be an object.

18:40.630 --> 18:43.960
This is going to be again, same date we have done it so many times.

18:43.960 --> 18:49.660
Shouldn't be a big deal and the default is going to be date dot now.

18:49.750 --> 18:51.040
Should I write this one?

18:51.190 --> 18:51.730
Yeah.

18:51.850 --> 18:53.410
Great that you have denied.

18:53.410 --> 18:54.820
No, we shouldn't be writing this way.

18:54.820 --> 18:55.840
We should be writing this.

18:55.840 --> 18:57.550
We don't want to execute it right now.

18:57.940 --> 19:03.670
Now, I can go ahead and remove this one now because it's of no use but helped us a lot.

19:05.050 --> 19:09.250
Now we don't really write too many of the methods and inside the mongoose model itself.

19:09.250 --> 19:14.200
But in case you want to go ahead and write more methods as simple something like tokens we have done

19:14.200 --> 19:17.080
in the eight of us, not eight of us in the user.

19:17.200 --> 19:22.460
Like JWT tokens and stuff, we can go ahead and do that, but in this case we won't be needing that.

19:22.480 --> 19:23.730
So quite a long video.

19:23.740 --> 19:25.870
Now, let's go ahead and catch up in the next one.
