WEBVTT

00:05.230 --> 00:07.060
I ever will come back.

00:07.060 --> 00:13.270
So and this is what we are going to be discussing what exactly is a database and why we need a database

00:13.360 --> 00:14.850
in our web applications.

00:14.860 --> 00:18.230
Why do we need to add it into our API or in general anything.

00:18.250 --> 00:18.810
Right.

00:19.060 --> 00:21.670
And so yes let's get right into it.

00:21.670 --> 00:25.160
So let's just define what exactly is a database.

00:25.230 --> 00:29.930
A database is just a structured set of data held in the computer.

00:29.950 --> 00:35.630
So it's you can think of it as a collection of data that is stored inside the computer.

00:35.650 --> 00:38.240
So why exactly is this useful.

00:38.440 --> 00:43.900
If you think about all the computers that we've been or all the web applications or API that we've been

00:44.080 --> 00:51.430
developing so far we basically have a server over here so I'll draw a server and then inside this server

00:51.430 --> 00:58.940
I have my application running and then the user is basically from his own browsers or lots of allright

00:58.990 --> 01:06.130
browsers and lots of users have browser one browser to all the way to lots of brothers and every one

01:06.130 --> 01:13.480
of them makes an HDTV request a miser right to request a specific page so HTP page.

01:13.540 --> 01:14.090
Right.

01:14.350 --> 01:21.180
But if you think about it this this mechanism over a year is only good for a few for a few cases right.

01:21.400 --> 01:27.940
Well if you think about any of the pages that you interact with usually not only that you just request

01:27.940 --> 01:30.470
to see some information you get it a little.

01:30.520 --> 01:37.060
Let's think about Facebook for example Facebook and Facebook you have to log in into your account and

01:37.060 --> 01:38.550
then you can post stuff.

01:38.560 --> 01:42.270
And if you close Facebook then this stuff is not gone right.

01:42.270 --> 01:46.620
You would expect that your posts would remain there until you delete them right.

01:46.740 --> 01:50.040
Or you hope at least that they would lead them right.

01:50.080 --> 01:51.990
So what exactly.

01:52.040 --> 01:55.180
How can we achieve this with what we know so far.

01:55.180 --> 01:58.340
So what we know so far is just a one way thing.

01:58.340 --> 01:59.770
Right we have a request.

01:59.830 --> 02:06.790
So we have a request and then this request is hey get or post this information to the server and the

02:06.790 --> 02:12.280
server has to do some computation over here and then reply me just the response right.

02:12.280 --> 02:18.160
And that's usually 200 and then maybe it's a J song file with some information for the browser.

02:18.160 --> 02:23.340
As we've discussed before now what about if this user wants to sign up.

02:23.470 --> 02:29.510
Well how do I know that this is the username and the correct user name and password for this user.

02:29.620 --> 02:32.390
Well they use it let's say the user tries to sign up.

02:32.530 --> 02:36.830
So he sends his information username and password over the Internet to me.

02:37.060 --> 02:41.080
And so now I have this username and password right.

02:41.130 --> 02:46.570
And I have to do some computation and tell him OK you're registered now but let's say he closes the

02:46.570 --> 02:48.610
browser and that opens it again.

02:48.610 --> 02:51.850
How do I know that this is exactly the same person right.

02:51.970 --> 02:58.900
If I want to know that well the only way I can know this is if I knew his username and I know his password.

02:59.050 --> 03:04.540
So if I don't know these two things if I don't know his username I don't know his password then I can

03:04.540 --> 03:10.300
verify right because this person might tell me hey I don't know if this username is cold.

03:10.480 --> 03:13.490
For example in his password is 1 2 3.

03:13.480 --> 03:18.670
So hopefully your password is not 1 2 3 but if this is the username and password then this guy might

03:18.670 --> 03:19.970
tell me hey I'm OK.

03:20.070 --> 03:22.280
Right a lot of me instead of this guy.

03:22.420 --> 03:28.770
So the only way we can verify this is if I store the username and password of this user somewhere.

03:28.990 --> 03:32.590
And that's exactly the idea of a database database.

03:32.620 --> 03:34.430
We're to put a database here.

03:34.510 --> 03:38.320
The whole idea of a database is to store these types of information.

03:38.380 --> 03:42.260
So a database you can think of it as a big document.

03:42.260 --> 03:42.490
OK.

03:42.520 --> 03:46.790
And it's full of fros row on row to all the way OK.

03:46.840 --> 03:52.650
Lots of rows and then each of these rows might have each of these customers might have a different idea.

03:52.660 --> 03:53.190
Right.

03:53.320 --> 03:58.120
And then a different username and then a different password.

03:58.360 --> 03:58.850
Right.

03:58.990 --> 04:01.780
Hopefully you don't store the password in plain text editor.

04:01.790 --> 04:09.220
God talk about that in later videos but this is the password or what they commonly call in in development

04:09.310 --> 04:13.410
the hashed password and so on.

04:13.450 --> 04:17.790
Lots of fields for example date of birth maybe and so on.

04:17.800 --> 04:23.590
So you'd have a book or a document that looks like this and then you whenever a new user or whenever

04:23.650 --> 04:29.290
a new user sends you that information from the registration form you would get this information and

04:29.290 --> 04:35.380
then you say OK I have a user name so I'm going to add a new row into my database so you communicate

04:35.380 --> 04:41.290
with the database while you're computing and then you say OK I'm going to put the ID the next ID's for

04:41.290 --> 04:48.520
example 3 and then I'm going to put the user name and his password so I'll just put some stars over

04:48.520 --> 04:50.450
here to denote the password.

04:50.590 --> 04:56.230
And then the date of birth and fill all this information into your database and then once you're happy

04:56.230 --> 04:58.010
with this once this information is.

04:58.150 --> 05:04.030
So once your database tells you OK right once your database tells you everything the story to hear then

05:04.030 --> 05:08.920
you can information and say hey you know what I've registered to you.

05:08.970 --> 05:14.610
So now the next time someone wants to log in if this guy is a sneaky guy and he tries to log in he tells

05:14.610 --> 05:21.720
you Hey I'm a and my password is you know is three to one for example that you and you would he would

05:21.720 --> 05:24.040
send you this information by a post.

05:24.180 --> 05:30.820
And then he would tell the database Hey do you have any user which which is called a and has this password.

05:30.870 --> 05:35.460
So you look here and then you would notice that this is not the password right because the original

05:35.460 --> 05:37.310
password is 1 2 3.

05:37.380 --> 05:42.060
So you add the database with all your ah I don't have this username and password.

05:42.060 --> 05:43.640
So you would reply this user.

05:43.790 --> 05:46.080
I'm sorry I cannot lie you end right.

05:46.080 --> 05:48.590
This is an invalid password.

05:48.840 --> 05:54.250
So in other words a database is just a document to keep track of things.

05:54.270 --> 05:58.980
Once the the the whole request and response is gone right.

05:58.980 --> 06:06.080
Because if you only rely on the response and the your request and the response then you can how long

06:06.270 --> 06:08.520
you lose a lot of information right.

06:08.520 --> 06:14.000
For example Facebook wouldn't be able if you'd get the post and then they don't store it somewhere.

06:14.000 --> 06:16.340
Then there's no way that this brand.

06:16.380 --> 06:20.130
Next time you log in then the Facebook will tell you sorry I did.

06:20.130 --> 06:21.340
I don't have a database.

06:21.340 --> 06:23.130
I didn't store it right.

06:23.160 --> 06:24.550
So so for all that.

06:24.590 --> 06:32.100
Although although AP is that we've been doing we have done only one API right support slash and slash

06:32.100 --> 06:37.380
divide or division and slash multiply and slash subtract right.

06:37.440 --> 06:43.270
And if you notice something about this API is that it doesn't need any information to be short and that

06:43.430 --> 06:47.400
the reason is well we don't have any.

06:47.420 --> 06:52.860
Well we don't we don't need to store anything right because the operations that these API were doing

06:52.860 --> 06:59.430
was basically just add divide multiply and subtract so they don't need any information they don't need

06:59.460 --> 07:01.240
any username password right.

07:01.380 --> 07:06.040
And your user who sends his request we can automatically handle his request right.

07:06.300 --> 07:07.770
But usually that's not the case.

07:07.770 --> 07:14.100
For example if your API is paid then you might want to store here how much how much money this user

07:14.100 --> 07:15.120
has in his credit.

07:15.120 --> 07:15.420
Right.

07:15.450 --> 07:23.730
Let's say you give this user $100 right and he tell him if you want more more to do more API calls then

07:23.730 --> 07:24.850
you need to pay more.

07:25.020 --> 07:31.640
Well this user might might if you if he wants to log in then he has to have his own username and password

07:31.640 --> 07:31.790
right.

07:31.790 --> 07:36.860
To make this call and to subtract a little bit from his money for every call.

07:37.170 --> 07:42.090
So that's the idea of a database really is that we need to store a lot of information or we need to

07:42.270 --> 07:48.900
store information about the customer mainly the customers and all the information about their usage

07:48.930 --> 07:49.680
of the service.

07:49.680 --> 07:52.570
For example some people might even have a difference.

07:52.620 --> 07:58.920
Michael this database one so people might have even a second database so let's call it a database too.

07:59.130 --> 08:05.030
And that inside this database do they would store different things for example customer I.D..

08:05.250 --> 08:14.220
Customer ID and then they would store the type of API calls or API call Vasos little bits smaller spacier

08:14.730 --> 08:22.080
and then you would say for example that user id 3 sent me an API call as Slash had at this date for

08:22.080 --> 08:22.800
example.

08:23.010 --> 08:25.980
And then he called slash multiply right.

08:26.040 --> 08:31.900
So some people might want to know OK what's the most famous API call that that the people are calling

08:31.900 --> 08:33.100
in my API right.

08:33.120 --> 08:35.580
And and for that you have to store it in the database.

08:35.580 --> 08:35.990
Right.

08:36.150 --> 08:42.990
So from now on whenever we think about we want to store something that the user sends us or that we

08:42.990 --> 08:43.690
calculate.

08:43.680 --> 08:49.710
So for example think about maybe a web application that does something that takes so much resources

08:49.710 --> 08:49.950
right.

08:49.950 --> 08:56.360
For example it has to compute the matrix multiplication of two huge matrices.

08:56.760 --> 09:02.460
So instead of having to calculate every time at crunch time we can just store it in a database and then

09:02.460 --> 09:05.400
one once we need it we can access it from the database.

09:05.400 --> 09:06.000
Right.

09:06.060 --> 09:13.410
So the whole idea is to store to be able to store many things like customer information customer usage

09:13.410 --> 09:19.080
of these things or even information that you might need right for for your application to run.

09:19.080 --> 09:23.580
For example you want to keep a counter of how many users are visiting your Web site.

09:23.580 --> 09:28.180
So every time you get a hit then you increase the counter in the database by one.

09:28.320 --> 09:33.480
So for example you got a request plus one and then you get a request again you see how many users you

09:33.480 --> 09:38.790
have and then you add one two plus two now and then you get another eques you see blustery so you add

09:39.130 --> 09:40.590
them plus three and so on.

09:40.770 --> 09:44.730
So anything that you want to store for a long term right.

09:44.730 --> 09:46.590
Not just during the computation.

09:46.590 --> 09:46.730
Right.

09:46.730 --> 09:52.290
So not anywhere or something that you want to store is usually stored in a database.

09:52.290 --> 09:54.660
So there's two types of database.

09:54.690 --> 09:57.590
There is mice or sequel.

09:57.650 --> 09:58.960
No and No.

09:58.980 --> 10:06.940
SIEGEL OK so we're using a no single database for our project it because it's much easier to deal with

10:07.130 --> 10:07.810
Jasons.

10:07.910 --> 10:10.790
So we will be using a no secret code.

10:10.820 --> 10:16.600
Mungo D-B So this one that you might have heard this in the is a famous database now and it uses the

10:16.600 --> 10:17.580
no sequel.

10:17.680 --> 10:21.810
So some examples of sequel databases might be my sequel right.

10:21.820 --> 10:25.110
You might have heard of my sequel This is the oldest type of data.

10:25.170 --> 10:28.950
A lot of the all this but it's very common in the industry to be used.

10:29.110 --> 10:36.070
But also Lovegood maybe starting to use a lot more because it's very fast almost as well not not the

10:36.070 --> 10:40.010
same speed as my sequel but it's very very comparable.

10:40.120 --> 10:46.510
And you know the Mongo baby or no sequel in general has a lot more advantages than sequel which will

10:46.510 --> 10:49.470
discuss it briefly and in a future.

10:49.930 --> 10:56.200
So hopefully this makes sense right where we're going to be you'd be using and no sequel database and

10:56.200 --> 10:58.950
this database is called Mongo NDB.

10:58.960 --> 11:05.020
Right so we're going to be explaining how to use more goodi be and that will use if you want like a

11:05.110 --> 11:11.290
heads up of what we're going to be use and we're going to use this Mongo D-B to make out an application

11:11.290 --> 11:14.000
to improve our application of slash add.

11:14.140 --> 11:19.540
But this time we're only going to allow users to use our API five times.

11:19.560 --> 11:20.100
Right.

11:20.350 --> 11:26.440
And then they have to also supplement apart from x and y they have to supplement also their username

11:26.680 --> 11:27.690
and password.

11:27.760 --> 11:33.110
OK so they have to supply both of these things before they can use the API.

11:33.220 --> 11:39.090
So if the user and if if some user uses the API more than five times then I'm going to reject it.

11:39.090 --> 11:43.080
I'm going to tell him hey you have to pay to go to another time five times.

11:43.090 --> 11:49.980
So hopefully this user infirm user information and password we're going to store in a Magdi database.

11:50.170 --> 11:58.420
And so we can keep track of how many and maybe also how many API calls this user has done.

11:58.450 --> 12:04.510
So for you we can keep track of how many calls that this user has done in the past.

12:04.510 --> 12:05.730
For example one month.

12:05.740 --> 12:06.790
Right.

12:06.820 --> 12:08.290
So yeah.

12:08.430 --> 12:13.220
We'll stop here and in the next video we're going to talk more about this so until the next video at

12:13.300 --> 12:13.810
decoding.
