Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,300 --> 00:00:10,330
Before we actually right, any Firestar database code, we have to understand a couple fundamental concepts
2
00:00:10,570 --> 00:00:14,410
about how fire stores database works.
3
00:00:15,400 --> 00:00:22,090
It'll help us also understand what it is that we're actually going to do from a coding perspective,
4
00:00:22,870 --> 00:00:29,130
but before that, in order for me to show you these concepts, we actually have to go into the database.
5
00:00:29,740 --> 00:00:36,490
The first thing we want to do is click this database tab inside of the develop sidebar.
6
00:00:38,130 --> 00:00:41,280
In here, we want to select create a database.
7
00:00:42,540 --> 00:00:46,830
And we'll get prompted with one of two options now.
8
00:00:47,750 --> 00:00:53,710
The first one is called lock mode, and the second is test mode, and this is essentially the beginning
9
00:00:53,720 --> 00:01:00,650
security rules that are set up for our new Cloud Firestar database when we create it.
10
00:01:01,610 --> 00:01:11,810
Locked mode essentially prevents any one from reading and writing to our storage test mode doesn't matter.
11
00:01:11,820 --> 00:01:14,810
It means that anybody can read and write to our database.
12
00:01:15,560 --> 00:01:17,540
Now, what does that mean?
13
00:01:17,990 --> 00:01:21,700
Well, this is one of those concepts on the right hand side here.
14
00:01:21,710 --> 00:01:26,150
You'll see what looks like an odd version of some JavaScript code.
15
00:01:27,230 --> 00:01:38,300
And what this says is this is kind of like a rule that we can write inside of our cloud firestorm that
16
00:01:38,300 --> 00:01:45,210
will either allow or deny different permissions of what people can do.
17
00:01:45,860 --> 00:01:47,080
What do I mean by this?
18
00:01:47,570 --> 00:01:57,680
Let's say you had a user that wanted to fetch all of the data related to the users, like they wanted
19
00:01:57,680 --> 00:02:00,950
a list of all the users while.
20
00:02:01,860 --> 00:02:08,070
If we were storing sensitive information on those users, we would not want anyone to be able to do
21
00:02:08,070 --> 00:02:10,370
that, let alone modify that data.
22
00:02:10,890 --> 00:02:19,860
So using this block of code here inside of our database, we're able to have the flexibility to control
23
00:02:20,190 --> 00:02:23,510
what people are able to do and not able to do.
24
00:02:24,000 --> 00:02:33,060
It's essentially like we're setting restrictions on what rules we want to enforce so that our database
25
00:02:33,060 --> 00:02:35,010
is as secure as possible.
26
00:02:36,510 --> 00:02:43,200
So we to begin want to start in test mode and we'll end up writing some rules so that we'll get more
27
00:02:43,200 --> 00:02:48,240
secure as we go, but we just want to explore this for now, so let's enable it.
28
00:02:49,750 --> 00:02:53,560
And it will end up creating our first database for us.
29
00:02:56,570 --> 00:03:05,180
Now, once we're in here, that rules tab is actually those things that I was talking about, this is
30
00:03:05,180 --> 00:03:08,450
where we'll see those rules.
31
00:03:08,450 --> 00:03:10,420
The first one, the on the right side.
32
00:03:10,430 --> 00:03:13,780
So here we can edit them, but we'll figure out that later, I promise.
33
00:03:14,510 --> 00:03:17,140
What we really want to see, though, is this data.
34
00:03:17,720 --> 00:03:19,760
So in Firestar.
35
00:03:20,730 --> 00:03:24,730
This database is what's called a no SQL database.
36
00:03:25,230 --> 00:03:32,580
It's essentially a fancy way of saying that our database consists of one gigantic JSON object.
37
00:03:34,090 --> 00:03:43,360
There are two types of data inside of our database, and they're more conceptual, so the first one
38
00:03:43,360 --> 00:03:44,620
is called a collection.
39
00:03:45,990 --> 00:03:56,430
A collection is exactly as it sounds, it's like a group of objects, except those objects are the second
40
00:03:56,430 --> 00:03:58,320
type of data called documents.
41
00:03:59,040 --> 00:04:02,400
So you can almost see them as an array of things.
42
00:04:03,150 --> 00:04:09,840
And each of those things can also have properties that point to other collections.
43
00:04:10,450 --> 00:04:12,630
So let's do an example.
44
00:04:13,170 --> 00:04:16,620
Let's say we add a collection called User's.
45
00:04:18,460 --> 00:04:19,490
We'll click next.
46
00:04:19,510 --> 00:04:27,910
And now we suddenly have this path inside of our database of users, and that is a collection.
47
00:04:28,870 --> 00:04:36,280
And in this collection, let's say we added a new document, in other words, a new user, we can auto
48
00:04:36,280 --> 00:04:45,820
generate the ID because every object or document needs a unique identifier so that we know that in the
49
00:04:45,820 --> 00:04:52,570
users, the document with this I.D. is that specific user.
50
00:04:53,800 --> 00:04:56,890
And then let's say they had a display name.
51
00:04:58,160 --> 00:05:00,230
Of the value eowa.
52
00:05:00,770 --> 00:05:10,880
So if I save this now in my collection of users, there is a document with the idea of what we just
53
00:05:10,880 --> 00:05:14,480
saw with the display name of this thing.
54
00:05:14,480 --> 00:05:18,050
You see on the right hand side is the document itself.
55
00:05:18,800 --> 00:05:24,340
And then inside of this document we can actually add a collection.
56
00:05:24,590 --> 00:05:30,680
So for example, let's say our user also had carte items, right?
57
00:05:30,890 --> 00:05:35,920
Like they pick some items and they added it to their cart, but they haven't checked it out yet.
58
00:05:37,410 --> 00:05:44,520
And in there will also generate a new ID because the first item they got was, let's say the name of
59
00:05:44,550 --> 00:05:47,010
the item was Blue Hat.
60
00:05:49,150 --> 00:05:58,780
So now inside of our users collection for this user of Yeva, he has a property which is a collection
61
00:05:58,780 --> 00:06:07,930
of card items, and in that collection of card items, there is a document of the cart item, blue hat.
62
00:06:08,620 --> 00:06:11,190
He could have multiple different items.
63
00:06:11,200 --> 00:06:14,430
Let's say he had another one, another one with a unique ID as well.
64
00:06:15,130 --> 00:06:18,850
And the name of that was leatherjacket.
65
00:06:21,070 --> 00:06:26,830
So here we see our car items collection on our user EOWA.
66
00:06:27,940 --> 00:06:32,950
Has this two items inside of it, two documents.
67
00:06:33,840 --> 00:06:43,260
So that's essentially the main thing in our database, it just consists of collections and documents
68
00:06:43,260 --> 00:06:47,490
and then those documents might have their own collections and documents.
69
00:06:51,120 --> 00:06:58,710
That's the idea behind how things are stored in our database, but the way that we would query for them
70
00:06:58,950 --> 00:07:00,180
is like so.
71
00:07:01,570 --> 00:07:08,860
Now, we already know that we have firebase imported and then we have our fire store and we remember
72
00:07:08,860 --> 00:07:13,990
exporting out Consed Firestar equals fire based firestorm.
73
00:07:17,650 --> 00:07:23,260
With this, how we actually query those documents is we would literally say something like Firestar
74
00:07:23,980 --> 00:07:25,180
collection, right?
75
00:07:25,180 --> 00:07:31,360
Because we need we want that collection and then we're saying users, what this will query for us is
76
00:07:31,600 --> 00:07:32,970
this collection.
77
00:07:33,340 --> 00:07:33,620
Right?
78
00:07:33,670 --> 00:07:37,510
It'll give us the identifier for this collection.
79
00:07:38,950 --> 00:07:47,860
If we wanted to say go into that users and then find this document, we would say Dot Doc and then we
80
00:07:47,860 --> 00:07:54,960
would pass it, the ID of that document that we're looking for, i.e. that user.
81
00:07:55,330 --> 00:08:01,390
So we're saying, Firestar, get me the collection called users and then get me the document with this
82
00:08:01,390 --> 00:08:01,840
ID.
83
00:08:02,740 --> 00:08:08,890
And then from here, we can even we can still keep chaining and say of that user document that you just
84
00:08:08,890 --> 00:08:09,310
got me.
85
00:08:09,550 --> 00:08:12,220
I want his collection of cart items.
86
00:08:14,590 --> 00:08:22,210
And then you can from here also do dock, right, and we can fetch that specific item we want whether
87
00:08:22,210 --> 00:08:28,870
we want the blue hat or the leather jacket, we would just copy that idea.
88
00:08:29,470 --> 00:08:36,220
What this is essentially saying is we're asking our store to get us the collection of users.
89
00:08:36,910 --> 00:08:42,030
And then from the collection, we want the specific document with this ID.
90
00:08:42,310 --> 00:08:50,410
So this specific user and then from that user, we want its property collection called car items.
91
00:08:51,220 --> 00:08:55,690
And from that car items, we want the specific document with this ID.
92
00:08:56,660 --> 00:09:04,790
By calling this chain, Firestar will end up getting us the object reference to this specific item nested
93
00:09:04,790 --> 00:09:11,900
inside of that user's user car items and then that specific car item.
94
00:09:13,180 --> 00:09:19,420
If we were to go back to our application now, the other way we could query for this specific document
95
00:09:19,960 --> 00:09:21,780
is if we did it like this.
96
00:09:22,420 --> 00:09:30,580
So if we wanted this specific document, we could also say Firestar doc and then slash users slash.
97
00:09:32,470 --> 00:09:37,560
This of car items, this idea.
98
00:09:39,230 --> 00:09:45,650
So this is equivalent to writing this, and if we wanted this collection of car items.
99
00:09:46,860 --> 00:09:53,160
It's exactly as you would imagine, instead of saying, Doc, we would say doc collection and then we
100
00:09:53,160 --> 00:09:57,510
would paste the string up until this point.
101
00:10:00,290 --> 00:10:07,100
So these are the two main methods of how we can get documents and collections from our database.
102
00:10:08,040 --> 00:10:14,670
Now that we know how to query for them, there will be ways and methods on these objects that we get
103
00:10:14,670 --> 00:10:20,190
that allow us to update them as well, but we'll see how to do that when we actually start implementing
104
00:10:20,190 --> 00:10:22,380
that code into our application.
105
00:10:23,210 --> 00:10:30,200
What we're going to do is we're going to store these authenticated users that we get back from our off
106
00:10:30,220 --> 00:10:36,860
library inside of our database, because right now these users are not actually being stored in our
107
00:10:36,860 --> 00:10:37,600
database.
108
00:10:38,030 --> 00:10:41,930
They're currently held inside of this authentication area.
109
00:10:42,530 --> 00:10:49,310
And Firebase is aware whenever a user signs in whether or not they've signed in before because it is
110
00:10:49,310 --> 00:10:50,420
storing those users.
111
00:10:51,080 --> 00:10:54,380
But we are not actually storing those users in our database.
112
00:10:54,380 --> 00:11:02,600
So there's no usage for us with those user objects in any relation to what we could do with them inside
113
00:11:02,600 --> 00:11:03,340
of our database.
114
00:11:03,800 --> 00:11:05,450
So let's see what we're going to do.
11530
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.