All language subtitles for 008 Modelling Reviews_ Parent Referencing_Downloadly.ir_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

In this video, let's continue to translate

the data model that we established right at the beginning

of the section into some actual code.

And so, this time we're gonna implement the reviews model.

So the first step is to create a new file

in the models folder and call it ReviewModel.js.

And to me, this looks like yet another great challenge

for you to practice some of the skills

that you already learned up to this point.

Okay so, in this challenge, I want you to create

the review model.

And what we need in there is actually very simple.

So let me put that here in a comment.

So we basically want a review,

so the text for the review.

We want a rating

so just like this.

Then we also want a createdAt

so with the current timestamp

and then we also want a reference to the tour

that this review belongs to

and also to the user who wrote this review.

Okay, so basically two parent references here, right.

And so with the stuff that you learned

in the last couple of lectures,

you should be able to actually complete this challenge

completely on your own.

So, pause the video now and good luck with that.

Now, okay, so I hope you didn't just skip this

and instead, you really implemented it by yourself

and anyway, this is how I created it.

So of course, we need to start by requiring mongoose

and then

the reviewSchema is equal to new mongoose.Schema.

And so let's start adding our fields.

So first the review is of course a string.

Now, right and of course, I'm doing this too fast,

so I also need to specify type

and then let's also set it to a required,

true,

review can not be empty.

Then we want a rating,

and this one is of the type number.

And the rating is ideally between one and five.

And so the minimum of one and the max is five.

So as you already know,

these are some simple validators.

That work only for numbers, right.

This is not correct here.

Okay.

Next up, the createdAt.

Into this is of type, date,

and by default we want

Date.now.

Okay.

So this was the easy part.

And lets actually also create a model

and export it before adding these references.

So const,

Review is equal too mongoose.model

with the name Review.

And then of course reviewSchema.

To finish of course module.export

equals the Review.

Alright, and now comes the reference part.

So a review of course needs to belong to a tour.

And it also needs an author.

Okay.

So that's again what we specified

in our data modeling lecture.

So basically that we were going to implement

parent referencing here in this case.

Because both the tour and the user

are in a sense the parents of this data set.

And we decided to do it this way

because we are going to potentially

huge erase any parent elements right?

So we should not design our application

thinking that there will only be a few reviews.

Only to then come back to it after some time

and find out that our assumptions were wrong.

And now we need to rebuild our entire data model.

So that would be terrible.

So in many situations, as you already know

what we do not really know, how much our erase will grow.

Then it's just best to opt for parent referencing.

So again, that's exactly what we're doing here

when we're referencing tour and user.

So lets actually now go ahead and implement that.

And starting with the tour.

Alright.

So here we need some space, and okay.

So the type is as we did before, mongoose,

and that's not correct.

So mongoose.Schema.ObjectId,

with a capital O and a capital I, but not the D.

And I'm just telling you that

because I once wrote ID like this,

and then spent half an hour trying to figure out

why my application wasn't working.

Okay, so this D needs to be lowercase.

Anyway.

The reference in this case is of course the tour.

And we also want to make this required.

So true and then Review must belong

to a tour.

Okay.

And just like this, each Review document now knows

exactly what tour it belongs too.

While the tour of course doesn't know initially

what Reviews and how many Reviews there are.

But that it a problem that

we will actually solve a bit later.

Okay.

Next up, when there is a Review, we not only

want to know what tour it belongs to,

but also who wrote this Review.

So user,

and again, the same type of

mongoose.Schema.ObjectId,

and this time

the reference, as you can imagine is gonna be user.

Okay, and again we make it required

because well, a review really cannot work

without an author basically.

And so review

must belong to a user.

Okay, that's actually it.

Alright.

Now just to finish lets actually also add these options

to the Schema where we make it so that virtual properties

also show up in Json and object outputs.

Okay.

So we did that before in the tours.

I'm not sure if we did it in the user model.

But anyway, here we are actually

gonna need it a bit later.

So we need to specify that.

Remember, basically what I mean

is this part.

So I'm actually going to go ahead and copy it.

Just to save us some time.

And so again, all this does is to really make sure

that when we have a virtual property,

basically a field that is not stored in the database

but calculated using some other value.

So we want this to also show up whenever there is an output.

Right, and so that's what we do here.

Okay.

And so I actually think that's actually it for now.

Very simple.

The only a bit tricky part is actually to create

these references here.

But we actually did that before

and so it really works in the exact same way.

So in the next video we will then use the Schema

in order to create some new reviews.

So see you then.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.