In the shell you can run show dbs to see which databases you have on this mongodb server
and as you can see, as I'm just starting out, I got no databases in there,
you might even just see admin and config here
if this is brand new
but that will be fine too,
you don't need to create any of these default databases.
The default databases here simply exist to store configuration for this database server
or for example the admin database will allow you to create users and roles and how people can use and
interact with the database,
all topics we'll cover later in the course.
So we got no database in here, we can switch to a database with the use command though and you can even
switch to databases which don't exist yet,
so for example here I want to start with some flight data, so I'll name it flights and you can choose
any name you want.
If you hit enter, you see that we switched to the db flights
but if I type show dbs, we still don't see that
even though I did switch to it.
The reason for this is that this database does not get created before we start entering data in there
but if we do start entering data, it will be created automatically and implicitly,
so we don't have to create the database in advance.
Now as you learned on that slide, we store data in collections, so we don't just need access to that database
but also to a collection.
Now we get our flights database and in there, let's say we want to store some flight data.
You can reference the database you're currently in,
so in our case the flights database here with db and then you chain commands by typing a dot and then
the command and one command in quotation marks is that
we type the name of a collection we want to interact with.
Let's say we have a flight data collection named like this and this name is also up to you,
now this is a collection which also doesn't exist yet
but just like a database, it will be created on demand
once we start inserting data. Now to insert data, we type another dot
and now we can type some query commands, commands that allow us to get data out of the collection would
be higher right now because there is no data in it or commands that allow us to add data and there we
got the insertOne command for example. As the name suggests, this inserts one document into this collection.
Now important, make sure you've got the casing and the name in general correct,
you don't have a typo in there,
it's one word with a capital O
and now between these parentheses at the end here, we pass the data we want to store.
Now a document is always defined with curly braces,
if you're coming from a javascript world,
you will know this syntax, there you also create objects with curly braces. To be very precise,
we're not creating a javascript object here but a json document and json documents are also delimited
or surrounded by curly braces.
Now in that document, we now have key value pairs,
now let's inspect how that looks like and how that works
before we finally add our data.