Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
This video will be the first
of the four CRUD operation videos.
So this first one is about creating new documents.
But before we start creating new documents,
let me actually address a concern that you might be having.
So maybe you're wondering,
why are we actually doing all this stuff in a terminal?
And how does this relate to our Express application
that we built in the last section?
Well, the answer for that is that right now,
I want you to learn the absolute fundamentals of MongoDB,
without the context of any application.
So really, completely outside of Node.js.
Because in theory, we could us MongoDB
with any other language or any other framework.
It doesn't have to be with Node.js,
and so I think it's actually a good idea
to learn MongoDB standing completely on its own,
without the context of any other language.
Okay?
Later on, we will of course connect
a MongoDB database with our application,
so that in the next section,
we can then actually start working with databases
inside of our Express application.
And by then we will use
a MongoDB driver just for Node Express,
so that we can use our JavaScript language
to interact with our MongoDB database.
All right?
But for now, let's just learn MongoDB without any of that.
All right?
So in the last lecture, we created a new database.
A new collection inside, called tours,
and then one new document in there.
Right?
Remember that?
And to do that, we used insert 1.
Remember that?
But now, let's actually create
two documents at the same time.
So that works like this.
db, with just again, the current database, then .tours,
which is the collection where we want
to add our new documents, and then .insertMany.
Okay?
And insertMany is gonna accept an array of multiple objects.
So an array, and then close it.
So an empty object, and that may actually
put the second empty object here also already,
and so all we need to do is to fill up these objects.
So name, this one is called The Sea Explorer.
It has a price of 497, and a rating of 4.8.
And then the next object.
Let's give it a name of The Snow Adventurer.
Which is one of the other nine tours that we have.
Then the price is a bit more expensive, 997.
And the rating is 4.9.
And actually, let's add another field here.
So, remember from the intro lecture
how I said that MongoDB documents are very flexible.
And so they do not all have to have the same structure.
Okay?
So we can have different fields in different documents.
And so let's add the difficulty here.
And set this one to easy.
Okay?
So that's it, let's hit return here.
And so we inserted two new documents,
and here we see the IDs that they got.
So these two auto-generated
unique identifiers for each of them.
Okay?
Now just to make sure, remember make db.tours.find,
and here indeed, we now have our three tours.
So that's the one we created in the last lecture,
and then the two that we just created.
Okay?
So that's actually it for this lecture,
just to recap, we used the insertMany function
to pass in an array of two objects,
or two documents that we wanted to create.
Okay?
So that's all I had for this one.
In the next one, we will then learn how to do
some advanced queries to search for data in our database.
So that's an exciting one, so let's move on immediately.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.