1 00:00:02,210 --> 00:00:09,660 In the shell you can run show dbs to see which databases you have on this mongodb server 2 00:00:09,760 --> 00:00:13,520 and as you can see, as I'm just starting out, I got no databases in there, 3 00:00:13,610 --> 00:00:16,100 you might even just see admin and config here 4 00:00:16,180 --> 00:00:17,440 if this is brand new 5 00:00:17,630 --> 00:00:19,150 but that will be fine too, 6 00:00:19,160 --> 00:00:21,740 you don't need to create any of these default databases. 7 00:00:21,740 --> 00:00:28,390 The default databases here simply exist to store configuration for this database server 8 00:00:28,550 --> 00:00:34,790 or for example the admin database will allow you to create users and roles and how people can use and 9 00:00:34,790 --> 00:00:36,390 interact with the database, 10 00:00:36,410 --> 00:00:38,660 all topics we'll cover later in the course. 11 00:00:38,840 --> 00:00:44,870 So we got no database in here, we can switch to a database with the use command though and you can even 12 00:00:44,870 --> 00:00:47,420 switch to databases which don't exist yet, 13 00:00:47,420 --> 00:00:53,990 so for example here I want to start with some flight data, so I'll name it flights and you can choose 14 00:00:54,080 --> 00:00:55,150 any name you want. 15 00:00:55,280 --> 00:00:58,100 If you hit enter, you see that we switched to the db flights 16 00:00:58,220 --> 00:01:01,450 but if I type show dbs, we still don't see that 17 00:01:01,610 --> 00:01:03,440 even though I did switch to it. 18 00:01:03,560 --> 00:01:09,220 The reason for this is that this database does not get created before we start entering data in there 19 00:01:09,230 --> 00:01:14,330 but if we do start entering data, it will be created automatically and implicitly, 20 00:01:14,330 --> 00:01:17,780 so we don't have to create the database in advance. 21 00:01:17,780 --> 00:01:23,990 Now as you learned on that slide, we store data in collections, so we don't just need access to that database 22 00:01:24,020 --> 00:01:25,820 but also to a collection. 23 00:01:25,940 --> 00:01:32,690 Now we get our flights database and in there, let's say we want to store some flight data. 24 00:01:32,690 --> 00:01:35,680 You can reference the database you're currently in, 25 00:01:35,720 --> 00:01:42,470 so in our case the flights database here with db and then you chain commands by typing a dot and then 26 00:01:42,470 --> 00:01:46,950 the command and one command in quotation marks is that 27 00:01:46,970 --> 00:01:50,720 we type the name of a collection we want to interact with. 28 00:01:50,810 --> 00:01:57,030 Let's say we have a flight data collection named like this and this name is also up to you, 29 00:01:57,170 --> 00:01:59,630 now this is a collection which also doesn't exist yet 30 00:01:59,630 --> 00:02:03,200 but just like a database, it will be created on demand 31 00:02:03,200 --> 00:02:08,180 once we start inserting data. Now to insert data, we type another dot 32 00:02:08,180 --> 00:02:14,210 and now we can type some query commands, commands that allow us to get data out of the collection would 33 00:02:14,210 --> 00:02:19,610 be higher right now because there is no data in it or commands that allow us to add data and there we 34 00:02:19,610 --> 00:02:26,940 got the insertOne command for example. As the name suggests, this inserts one document into this collection. 35 00:02:26,980 --> 00:02:32,090 Now important, make sure you've got the casing and the name in general correct, 36 00:02:32,090 --> 00:02:33,420 you don't have a typo in there, 37 00:02:33,440 --> 00:02:35,450 it's one word with a capital O 38 00:02:35,660 --> 00:02:40,920 and now between these parentheses at the end here, we pass the data we want to store. 39 00:02:41,000 --> 00:02:44,970 Now a document is always defined with curly braces, 40 00:02:45,170 --> 00:02:47,270 if you're coming from a javascript world, 41 00:02:47,390 --> 00:02:53,000 you will know this syntax, there you also create objects with curly braces. To be very precise, 42 00:02:53,000 --> 00:02:59,840 we're not creating a javascript object here but a json document and json documents are also delimited 43 00:02:59,930 --> 00:03:03,390 or surrounded by curly braces. 44 00:03:03,410 --> 00:03:08,570 Now in that document, we now have key value pairs, 45 00:03:08,570 --> 00:03:11,810 now let's inspect how that looks like and how that works 46 00:03:11,870 --> 00:03:13,670 before we finally add our data.