1 00:00:01,770 --> 00:00:10,230 All companies store data from a simple record book of a small business, maybe even on a journal or 2 00:00:10,230 --> 00:00:17,220 a piece of paper to massive companies like Amazon that need computers to store petabytes of data. 3 00:00:17,670 --> 00:00:25,590 Now, in order to store this information, pretty much every company and sometimes individuals to need 4 00:00:25,590 --> 00:00:27,090 something called a database. 5 00:00:27,930 --> 00:00:33,870 We saw in the last section how hard it was to have our server remember a new user. 6 00:00:33,990 --> 00:00:39,570 Every time the server crashed, the variable will get reset and then it would start all over. 7 00:00:40,320 --> 00:00:48,420 Or if we wanted to do a login or a sign and check and iterate through the emails and passwords, doing 8 00:00:48,420 --> 00:00:51,410 a loop through JavaScript, that's inefficient. 9 00:00:52,020 --> 00:00:53,940 That's where database come to the rescue. 10 00:00:54,860 --> 00:00:58,430 So let's ask ourselves, what is a database? 11 00:00:58,760 --> 00:01:00,890 A database is a collection of data. 12 00:01:01,880 --> 00:01:07,160 And what we mean by data, there are many forms of them, right, there can be numbers, there can be 13 00:01:07,160 --> 00:01:11,810 dates, there could be password hashes, there could be user information. 14 00:01:12,790 --> 00:01:20,560 Databases allow us to organize this data in a way that is useful to us, and it makes data management 15 00:01:20,560 --> 00:01:21,040 easy. 16 00:01:22,480 --> 00:01:28,870 And something came out of that, and it's called Database Management System, or DBMS for short. 17 00:01:29,840 --> 00:01:36,560 It's a collection of programs which allows us to access databases and work with data, and it also allows 18 00:01:36,560 --> 00:01:39,530 control access to database users. 19 00:01:41,460 --> 00:01:45,330 So a DBMS is something in this box. 20 00:01:46,670 --> 00:01:52,190 Something that allows us a tool, a piece of software that allows us to communicate. 21 00:01:53,210 --> 00:02:01,820 With the database store information that's useful for us and also allows us to update, insert, delete, 22 00:02:02,360 --> 00:02:10,400 Look-Up, whatever's in the database, and this idea of a DBMS really started to take shape in 1960s 23 00:02:10,639 --> 00:02:13,630 and now it is at the forefront of many exciting things. 24 00:02:14,030 --> 00:02:19,610 There's an entire industry of engineers that just work with databases because it is so important. 25 00:02:20,950 --> 00:02:27,070 Now, there are two types of DBMS that are really popular right now and that we're going to talk about 26 00:02:27,070 --> 00:02:27,700 in this course. 27 00:02:29,630 --> 00:02:35,490 And these two types are represented really well by postscripts and Mongo DB. 28 00:02:36,320 --> 00:02:40,340 Let's talk about the first one, which is relational database. 29 00:02:40,910 --> 00:02:42,650 And this is probably the most popular. 30 00:02:42,890 --> 00:02:44,560 As you can see on the right hand side. 31 00:02:44,570 --> 00:02:52,460 You see that all of these are relational databases, postgrads Oracle, SQL Server. 32 00:02:52,730 --> 00:02:55,790 You may have heard of MySQL, Escorial Lite. 33 00:02:57,120 --> 00:03:04,770 These are all types of databases that have this relational database tag to them, and the beauty with 34 00:03:04,770 --> 00:03:06,720 them is that they're all pretty much similar. 35 00:03:06,730 --> 00:03:09,990 They all follow the same standard format. 36 00:03:10,530 --> 00:03:17,610 Relational databases consist of two or more tables with columns and rows. 37 00:03:19,390 --> 00:03:27,130 So in this case, users is a table and full name, user name text created at our columns and whatever 38 00:03:27,130 --> 00:03:30,130 values they have here are rows. 39 00:03:31,120 --> 00:03:33,910 Each row represents an entry in each column. 40 00:03:34,090 --> 00:03:38,620 So it's a very specific type of information like name, address or phone numbers. 41 00:03:39,770 --> 00:03:42,950 And then the relation between tables and field. 42 00:03:44,010 --> 00:03:51,450 It's called a schema in a relational database, the schema must be clearly defined before any information 43 00:03:51,450 --> 00:03:52,110 can be added. 44 00:03:53,420 --> 00:03:57,950 And if this is confusing right now, don't worry, we're actually going to create these databases, 45 00:03:57,950 --> 00:03:58,910 so it makes sense to you. 46 00:03:59,390 --> 00:04:05,310 If we had Twitter, for example, you can see over here the types of tables that we would have and how 47 00:04:05,310 --> 00:04:06,290 we would organize it. 48 00:04:07,100 --> 00:04:11,150 We would have a user stable, a tweet table, a following table. 49 00:04:12,780 --> 00:04:19,110 And we can connect all this information, for example, by connecting different pieces of the table. 50 00:04:20,040 --> 00:04:25,950 For example, the user name will be the same in the users table as it is in the tweets table. 51 00:04:27,450 --> 00:04:37,530 That way, we can say that the username and the tweets table is the foreign key of the username in the 52 00:04:37,530 --> 00:04:40,080 user's table and then from user. 53 00:04:41,050 --> 00:04:44,590 Will be the foreign key of username in the following table. 54 00:04:45,960 --> 00:04:56,130 Now, things like full name or ID, something that identifies each row in a table, is called a primary 55 00:04:56,130 --> 00:04:59,010 key and we'll go through that later on in the section. 56 00:05:01,820 --> 00:05:07,070 All right, so all these databases we're going to learn about postcrisis cual, but they're all pretty 57 00:05:07,070 --> 00:05:07,590 much the same. 58 00:05:07,610 --> 00:05:10,760 So once you know one, it's fairly easy to pick up the other ones. 59 00:05:11,630 --> 00:05:17,030 How do they actually communicate with a server with the back end? 60 00:05:17,660 --> 00:05:22,040 Well, all relational databases use something called obscure. 61 00:05:26,350 --> 00:05:33,340 And ask you all allows us to communicate, just like HTP did between the front end and the back end 62 00:05:34,240 --> 00:05:42,130 with you all were able to communicate with the database and modify or get or update however we want. 63 00:05:42,880 --> 00:05:45,100 And we'll have a video on this topic as well. 64 00:05:45,490 --> 00:05:45,760 All right. 65 00:05:45,760 --> 00:05:48,970 So that's relational databases. 66 00:05:49,690 --> 00:05:50,740 What about the second type? 67 00:05:51,680 --> 00:06:00,230 The second type is called a non relational database or a no ESKIL database, and once again, there 68 00:06:00,230 --> 00:06:05,630 are many, many different types of databases with some cool names like Kotb and Hyper Table. 69 00:06:06,680 --> 00:06:12,740 Now, a Mongo DB or a non relational database lets you build an application without having to define 70 00:06:12,740 --> 00:06:16,430 the schema first, unlike a relational database. 71 00:06:18,450 --> 00:06:27,640 If we go back to relational database, this schema or these tables have to kind of be predefined, right? 72 00:06:27,660 --> 00:06:35,730 We need to know how our app is going to look, make these tables so that once the app is public, we 73 00:06:35,730 --> 00:06:39,600 can start entering user information and tweets and followers. 74 00:06:41,580 --> 00:06:48,960 With a no excuse or non relational database, we can just define it as we go and they all have different 75 00:06:48,990 --> 00:06:51,180 ways of storing this information. 76 00:06:51,180 --> 00:06:52,980 So each one is very, very different. 77 00:06:53,290 --> 00:06:58,590 And this is another powerful reason to use a non relational database, is that if your data requirements 78 00:06:58,590 --> 00:07:04,770 aren't clear at the outset of your project and maybe you have a massive amount of unstructured data, 79 00:07:05,550 --> 00:07:11,120 you may not have the luxury of developing a relational database with a clearly defined schema. 80 00:07:11,370 --> 00:07:18,330 They offer instead a greater flexibility in that a non relational database are more like folders, just 81 00:07:18,330 --> 00:07:20,910 assembling related information of all types. 82 00:07:22,230 --> 00:07:30,630 Now, Mongo DB is something called document oriented, it stores information as documents. 83 00:07:31,620 --> 00:07:33,360 Let me illustrate this point to you. 84 00:07:33,570 --> 00:07:36,660 I have my desktop here with two folders. 85 00:07:37,420 --> 00:07:44,250 One is a really relational database and here have users tweets, profile following. 86 00:07:45,180 --> 00:07:52,560 And you can think of relational databases with this type of storage where this folder live somewhere 87 00:07:52,590 --> 00:07:58,950 on a computer that stores this information, and any time we need to ask a database for something, 88 00:07:59,280 --> 00:08:00,690 well, we grab the users. 89 00:08:00,810 --> 00:08:06,720 And if we also want to grab the tweets of the user, we find the user that we're interested in, then 90 00:08:06,720 --> 00:08:13,830 find the tweets of the user that we're also interested in with the foreign key that links to the users. 91 00:08:14,130 --> 00:08:18,320 And we can also find however many followers that user has. 92 00:08:18,540 --> 00:08:22,950 We grab that information and display it on our Web app. 93 00:08:25,360 --> 00:08:32,980 Mongo DB, on the other hand, will actually have each user as a document. 94 00:08:34,140 --> 00:08:40,320 So if I wanted to grab the first user, well, I just grabbed this document and it has all the followers, 95 00:08:40,320 --> 00:08:44,940 the tweets, the profile, everything is in this one document. 96 00:08:46,220 --> 00:08:51,530 And you might be thinking Mongo DB looks like a better choice than having this. 97 00:08:52,950 --> 00:08:54,140 Way of doing things right. 98 00:08:55,440 --> 00:08:59,700 Well, it depends on your need, and that's why database's is such a complex topic. 99 00:08:59,880 --> 00:09:01,970 It really, really depends on your situation. 100 00:09:02,340 --> 00:09:08,820 You can see this Mongo DB way being very useful if you have something like a profile, maybe a LinkedIn 101 00:09:08,820 --> 00:09:09,260 profile. 102 00:09:09,510 --> 00:09:14,970 But if you needed something where you're working with just following data or just tweets data, maybe 103 00:09:14,970 --> 00:09:18,840 with the tweets you want to see what is the average tweet size? 104 00:09:19,020 --> 00:09:25,500 Well, it's really easy to just grab this file and calculate that versus this way where you might have 105 00:09:25,500 --> 00:09:28,550 to extract it from each one of the users. 106 00:09:28,890 --> 00:09:30,330 So it really depends on your needs. 107 00:09:31,910 --> 00:09:34,880 Let me show you another diagram that might be. 108 00:09:36,710 --> 00:09:37,220 Useful. 109 00:09:38,780 --> 00:09:46,190 When we look at relational versus non relational databases, you can think of relational as each table 110 00:09:46,190 --> 00:09:54,230 has a blog post, a blog tag, a blog comment, and it links these tables to give you the blog information 111 00:09:54,890 --> 00:10:02,120 versus a non relational that stores this entire blog post in an entry and has comments, tax categories 112 00:10:02,390 --> 00:10:05,480 and all other related data just in one single place. 113 00:10:05,840 --> 00:10:08,480 So what does Mongo DB use to communicate? 114 00:10:09,290 --> 00:10:16,070 If we go back to our example here, we had ask you all for relational databases such as postcrisis or 115 00:10:16,100 --> 00:10:16,550 Mongo. 116 00:10:16,550 --> 00:10:26,710 DB has its own what we call query language, and it is just the Mongo DB query language. 117 00:10:31,560 --> 00:10:36,330 But they both aim to do the same thing, that is to communicate with the database, provide an easy 118 00:10:36,330 --> 00:10:40,530 way for the server to communicate with the database. 119 00:10:41,640 --> 00:10:46,230 And in this section, we're going to be talking about that and we're going to finally connect the dots 120 00:10:46,710 --> 00:10:50,520 and show you the power of databases once they're connected to a server. 121 00:10:51,410 --> 00:10:52,370 I'll see you in the next one.