1 00:00:02,630 --> 00:00:08,300 So what is mongodb? Mongodb is most importantly, a database. 2 00:00:08,300 --> 00:00:09,230 It's a database 3 00:00:09,290 --> 00:00:14,890 but the company behind mongodb which is focused on that database and a couple of other products which 4 00:00:14,890 --> 00:00:17,300 I'll also talk about in this course, 5 00:00:17,360 --> 00:00:23,090 so the company behind that is also called mongodb but with mongodb, I of course mean the database. 6 00:00:23,190 --> 00:00:29,900 Now the name is stemming from the word humongous because this database is built to store lots and 7 00:00:29,900 --> 00:00:35,990 lots of data and not just from a data size perspective but also in a sense of you can store lots of 8 00:00:35,990 --> 00:00:41,010 data and you can then work with it efficiently which of course also is super important, 9 00:00:41,030 --> 00:00:43,660 so this is mongodb, it's a database solution. 10 00:00:43,690 --> 00:00:45,940 Now of course we already got database solutions, 11 00:00:45,980 --> 00:00:48,320 we've got mySQL, we've got postgres, 12 00:00:48,380 --> 00:00:51,020 we've got thousands of database solutions already, 13 00:00:51,020 --> 00:00:53,540 so how is mongodb different? 14 00:00:53,960 --> 00:01:00,080 Well mongodb of course also is most importantly a database server that allows you to then run different 15 00:01:00,080 --> 00:01:01,520 databases on it, 16 00:01:01,520 --> 00:01:06,290 so we might have a shop database running on our mongodb server because the mongodb 17 00:01:06,290 --> 00:01:10,940 environment basically gives you a server which you start and which you can then create multiple databases 18 00:01:11,090 --> 00:01:11,620 using 19 00:01:11,630 --> 00:01:12,250 mongodb. 20 00:01:12,560 --> 00:01:19,310 So we have a shop database, in the mySQL world, we also have databases and in such a database, we would 21 00:01:19,310 --> 00:01:22,880 have tables, in mongodb we have so-called collections, 22 00:01:22,880 --> 00:01:26,210 so in our shop, we might have a users and an orders collection, 23 00:01:26,210 --> 00:01:30,430 we probably would also have a products collection but this is just an example of course, 24 00:01:30,620 --> 00:01:35,990 so we have these collections inside our database and you can have multiple databases and multiple collections 25 00:01:35,990 --> 00:01:37,390 per database. 26 00:01:37,550 --> 00:01:42,620 Now inside of a collection, you have so-called documents which look like this, 27 00:01:42,620 --> 00:01:47,670 now these documents if you are having a javascript background might look familiar to you, 28 00:01:47,870 --> 00:01:53,830 they look like javascript objects and indeed this is basically how you store data in mongodb, 29 00:01:53,960 --> 00:01:59,720 you use this document format, this object format as you know it from javascript and you might even 30 00:01:59,720 --> 00:02:04,260 notice here that inside a collection, you are schemaless, 31 00:02:04,350 --> 00:02:10,190 this second document does not look like the first one, the age is missing and this is a flexibility mongodb 32 00:02:10,190 --> 00:02:11,220 gives you. 33 00:02:11,330 --> 00:02:17,780 It is really all about flexibility, where SQL based databases are very strict about the data you 34 00:02:17,780 --> 00:02:20,440 have to store in there, mongodb is more flexible, 35 00:02:20,570 --> 00:02:25,700 you can store totally different data in one and the same collection and therefore, your database can 36 00:02:25,700 --> 00:02:29,570 grow with your application and your application needs. Of course, 37 00:02:29,600 --> 00:02:34,820 typically you will have some kind of structure in one collection because your app typically requires 38 00:02:34,820 --> 00:02:39,920 some type of structure to work with the data and in this course, we'll actually have a whole module where 39 00:02:39,920 --> 00:02:44,900 I talk just about data structures and relations, where I will make it clear how you can structure it, 40 00:02:45,140 --> 00:02:50,480 how you can follow best practices, how you want to structure different related data and so on 41 00:02:50,810 --> 00:02:56,180 but you are schemaless and that is one important thing. Now inside a document as I mentioned, you 42 00:02:56,180 --> 00:03:00,450 use these javascript objects to store your data, to be precise, 43 00:03:00,530 --> 00:03:07,580 you use a format called json and this is how a document would look like. In json, a single document is surrounded 44 00:03:07,580 --> 00:03:13,700 by these curly braces and you will see that once we start working with it and then we have our keys 45 00:03:13,760 --> 00:03:14,430 in there, 46 00:03:14,480 --> 00:03:21,260 so that would be a key and key consists of a name of that key here, which has to be surrounded in double 47 00:03:21,260 --> 00:03:27,590 quotation marks so name, age, address and hobbies would be key names here or also keys, I'll also refer 48 00:03:27,590 --> 00:03:29,570 to them as just keys, 49 00:03:29,570 --> 00:03:32,920 then we have a colon and then we have the value of that key. 50 00:03:33,140 --> 00:03:37,940 So here we have Max which would be some text string and therefore also has to be enclosed in double 51 00:03:37,940 --> 00:03:38,810 quotation marks 52 00:03:38,990 --> 00:03:43,580 but you can also store numbers without quotation marks then, you could store booleans, 53 00:03:43,610 --> 00:03:44,670 true or false 54 00:03:44,750 --> 00:03:50,930 and you can even store nested data as you can see. The address key or field as you could also call it 55 00:03:51,200 --> 00:03:52,980 has an embedded document, 56 00:03:53,060 --> 00:03:56,890 so this again has curly braces in there and then another key value pair. 57 00:03:57,110 --> 00:04:02,810 And this is another cool feature of mongodb and it's documents, you can store nested data in there 58 00:04:02,960 --> 00:04:04,180 and why is that helpful? 59 00:04:04,310 --> 00:04:10,490 Well this allows you to create complex relations between data and store them in one and the same document 60 00:04:10,760 --> 00:04:14,750 which makes working with it and fetching it super efficient, 61 00:04:14,750 --> 00:04:20,710 where in SQL, you have to write complex joins to find data in table A and data in table B, 62 00:04:20,810 --> 00:04:24,650 here you can fetch it all in one document and you're good to go, 63 00:04:24,650 --> 00:04:29,850 so this is highly efficient and allows you to store data in a logical way. 64 00:04:29,970 --> 00:04:34,240 Hobbies shows you another example of data you can store in a document, 65 00:04:34,280 --> 00:04:38,770 here we have a list of embedded documents and you could also have a list of strings or numbers, 66 00:04:38,810 --> 00:04:46,290 so storing list is also possible and this altogether is in one document inside a collection. Now in 67 00:04:46,340 --> 00:04:49,270 title it also says bson instead of json, 68 00:04:49,400 --> 00:04:55,250 well behind the scenes on the server, mongodb converts your json data which is this format you 69 00:04:55,250 --> 00:05:01,130 see here to a binary version of it which can basically be stored and can queried more efficiently, 70 00:05:01,130 --> 00:05:06,750 you don't need to worry about that, we work with this json something, we work with this object thing throughout the 71 00:05:06,750 --> 00:05:07,560 course. 72 00:05:07,890 --> 00:05:09,030 So this is the data we store, 73 00:05:09,030 --> 00:05:15,180 this is a document and the whole theme of this video and of mongodb really is the flexibility 74 00:05:15,450 --> 00:05:18,240 and the optimisation for usability 75 00:05:18,360 --> 00:05:24,660 and that is really what sets mongodb apart from other database solutions and which makes it so awesome 76 00:05:24,750 --> 00:05:30,660 and so efficient from a performance perspective too because you can query data in the format you need it 77 00:05:30,810 --> 00:05:33,630 instead of running complex restructurings on the server.