So here is some data I prepared,
now you'll find that data attached to this video by the way.
It is a
json file and this json file actually holds an array
hence the square brackets here of two json documents,
so this is one single json document and this is another json document and we entered one such document
with insertOne, we don't insert both.
We insert one such document with insertOne and this would be one piece of information about a flight.
Now here, I got these key value pairs and that is how a json document is basically made up of, you
have names which you enclose between double quotation marks and these double quotation marks are important
and have to be used and then you got the values for these names or keys and here, the values can be different
kinds of data.
Here we got a string,
so some text basically which is surrounded by quotation marks.
Here we got a number though
and there we don't have quotation marks,
so the values don't have to use quotation marks, only the names here.
The values can be strings and then they have quotation marks but they can also be numbers or like this,
a so-called boolean,
so true or false,
this also has no quotation marks.
There also are some other types of data which we'll see throughout the course,
these are three very important types of data which you will use a lot though,
so this is one json document we could enter.
So let's grab this document,
again you'll find this file attached and just that one document including the curly braces but not the entire
array,
grab that document and then back in your terminal here, you can copy that document between those braces,
important before you copy it in, delete the closing parentheses,
then add it and then close it.
Now if you hit enter, you should see this message here which basically tells you that this was accepted and
was inserted successfully and that it also assigned an automatically created ID.
Now that's a feature provided by mongodb,
every document you enter gets a unique ID and actually, you need to have a unique ID on every element
but as you saw here, you don't need to specify it on your own, mongodb gives you one, it's of type objectId
so this another type supported by mongodb which we can use and we can see it if we now simply have
a look at our flight data.
Let me clear the console
and again if I now access flight data, so this collection, now instead of inserting, we can use find like
this
and if we use it like this, it will simply return all the documents in this collection.
You can also add another dot and then pretty as a function
and this will just make sure that the output we get back is formatted in a pretty way.
That's the only thing it does, find without pretty will also work,
it'll look like this but and you can press arrow up to repeat your last command,
if you add pretty, it looks like this which is easier to read and there we see all the data we entered
plus this extra _id which was added automatically by mongodb
and this objectid object is simply a special type of data provided by mongodb which is a unique
ID that also allows you to sort your documents because it will also have some time stamp data in there
you could say. So this id also can be used for sorting because it's guaranteed that if you would add
another document right now, this would be treated as a more recent document than this document we see
here due to that id.
But that's some behind the scenes stuff,
the important part is we got our data in there,
you still see we have the same data types we added like the number still is a number,
there are no quotation marks around it
and this is now valid json data inserted into our database or into our collection in that database
to be precise.