All language subtitles for 008 Inserting Comments Into The Database_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
fa Persian Download
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

So now that we're storing a newsletter successfully,

let's also store and fetch our comments.

For this I'll go back to the comments API route,

and now here we also wanna connect with MongoDB,

and then simply insert a new comment or fetch all comments.

So either way, no matter what happens,

we wanna connect to MongoDB.

So before we dive into any if block here,

I wanna set up my connection.

Hence, we need to import

MongoClient

from mongodb here,

and then repeat the code from before.

And of course we definitely could also look

into creating some helper functions,

but I will just quickly repeat that.

MongoClient connect, and then grab my connection string

from the newsletter js file.

Paste it in here.

And again I'll use async await.

So add async in front of the handler function,

and await disconnection to get access to the client.

Now already after all these if checks, I will go down there

and already call client close to make sure

that we don't forget this.

That we close the connection once we're done with our logic

no matter what our logic was.

So now that's that.

Now inside of request method POST,

we wanna store our comment here in our database.

And for this I'll create my new comment,

but then thereafter, I will use the client

and the db method to get access to the database

to which we connected.

And for that actually,

I wanna adjust the connection string here,

and not connect to a newsletter database,

but instead to my comments database.

Or, overall, we connect to our events database

for the events application.

And then we have our emails collection

and we have our comments collection.

And I think that makes more sense.

So I'll connect to the events database

in the newsletter js file as well,

and connect to the same database here

in the comments API route, events.

So then it's this database which will work,

and on that database, I then use the emails collection

in the newsletter js file,

or maybe let's now name the collection newsletter.

But that's of course up to you.

And in the comments event id file here,

I'll connect or I'll work with a collection named comments.

And here I now wanna insert one new comment.

Now it is this comment,

but I wanna tweak that comment object.

I don't wanna create my dummy id anymore,

because MongoDB will create a unique id for me.

So I don't need to assign my own id.

But instead I wanna do something

which I haven't done up to this point.

I want to use this event id which we're getting,

which is encoded in the URL.

And I wanna make it clear

to which event my comment is related.

Because in reality,

we would probably manage our events with MongoDB as well.

We're not doing that here,

but in reality we would probably manage them

in the database as well.

So then, storing the id of the related document

in some other collection in this document here

would make a lot of sense.

And that's definitely what I'll do.

I'll store eventId as a extra property

in the new comment to have this reference to the event

to which this comment belongs.

And then it's this new comment which I wanna insert.

So here I'll insert one, and I'll insert this new comment.

And of course await this operation.

Now we do get back some response here by the way.

Some result of that insert one operation,

and I will console log that result for now.

In the effort that's now my code here in the post case

so that we add a new comment.

Before we work on the get case here, let's save that code

and let's see whether it works and makes sense.

For this I'll dive into an individual event,

show my comments, and add a new comment

with some dummy data.

This is a test with MongoDB.

Click Submit.

We still get no feedback here.

We could add it,

but we haven't done anything in that direction.

But if I go the back end, that looks good.

I got a output here.

That's this result which I'm logging.

Whoops.

This result which I'm logging, that's what we see here.

And we see that it's quite a long result.

Quite a detailed output because result in case of insert one

is actually containing full details

about the operation that was performed,

but then also the connection in general and much much more.

Now what we can see if we go to the cluster

is that here if we reload this page to refresh the data,

we got this events database now with a comments collection,

and in there we indeed see that comment which I just added.

So it was stored successfully in the database.

Now what's also interesting on the result

is that on the result we also get back that unique id

which was generated automatically.

That's interesting because that means that

on the new comment object, which we stored in the database,

we can now add a id field

and set this equal to result.insertedId.

So that the new comment which we sent back

to the front end also contains this unique id

that was generated.

I guess that's convenient to have in case we would work

with that inserted comment on the front end right away.

So that's now the post case.

Let's now work on the get method where we get our comments.

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