All language subtitles for 011 Handling Duplicate Database Fields_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
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

Let's now handle the error

that occurs when we try to create duplicate fields

for fields that are actually supposed to be unique.

And so, remember,

that this is the type of error

that we get.

So, we tried to create a new tour

with a name that already exists

and the name fields is supposed to be unique

and so we get this error.

Now this error here doesn't have

a name property, okay?

And that's because, as I mentioned before,

it is actually not an error

that is caused by a Mongoose.

But instead, really, by the underlying

MongoDB driver, okay?

And so, what we're gonna do

to identify this error

is use this 11,000 code here.

All right?

So, we have one handler for the CastError.

Let's now create one for the case

that we have that error.code,

.code equal to 11,000.

So in that case, all error should be equal

to the error returns from handleDuplicateFields

and again, I'm adding DB here

just so we know that this has to do with our database.

All right?

And, so let's now actually then create this function.

And now, the message that we're gonna send

is this one so let's create it here.

And so I want it to say,

Duplicate field value, and then hear the name

of that value, so let's put that to x for now.

We will generate that a bit later.

So please use another value.

All right?

And so in the case that we just saw,

this x here should be called the Forest Hiker.

So basically, what we're trying to get

out of this error message string here

is this, "The Forest Hiker."

So that is the duplicate value

that we want to send to the client

so that they can now correct it

and create another name.

So, how can we actually extract

this piece of the string here?

Well, we're gonna use a regular expression

to, basically, as I just said,

find the text that is between quotes.

'Cause here in this string, all we have really

to identify this text here,

so to find it, is these quotes.

All right?

And now, as you already know,

regular expressions can be really tough.

And so I usually just Google them

and so let me show you how I actually do that.

In this case, I would simply search

for regular expression match text between quotes.

And then usually it's right the first result.

And then down here we have the result

and so we can use simply this regular expression.

Now I see that we have down here this here.

This also works and it's easier to read.

And it has a bunch of up votes

and so we simply can use this one.

So that should work as well.

So let's copy it and let's go back to our code,

and say that our value,

so const value is equal to the error.ermsg,

so remember, that that was the name of the property.

So, errmsg. So again, that's because

this is an error created by Mongo

and so these is slightly different names.

Okay?

So we have this string and now here we want to match

our regular expression.

So, match, and then in JavaScript,

a regular expression is always between two slashes.

Then paste it here what we just got from Stack Overflow

and let's actually take a look.

So, we're running already in production.

Right now we will not send back any response.

All I want to do now is to take a look at the value.

So, if I sent this now we get this weird response here.

And again, that's because we're not sending any error.

But for now I was really just interested in the value.

And so this, what we see here

in the log now is that value.

And actually it is an array.

But what we're interested in is actually this string here.

So it did actually match all the text

that was between strings and so,

we can say that it worked.

So our regular expression worked.

Now, all we have to say is that we want

the first element of that array.

So, element zero.

And now, let's actually go ahead and return

or new AppError, so new AppError,

paste in the message,

and again the 400 status code for a bad request.

And so let's now try that again.

Again, we are still running a production

and so that code should now run.

And of course, we tried to replace our x.

Of course, we now want our value here.

And so, now we get duplicate field value,

"The Forest Hiker."

Perfect.

And now, next up, in the next video

we will then handle the last of the three errors

which are the validation errors.

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