Hi, Alex here from rebeloper.com and welcome back to the channel and welcome back to
the second episode of fire store tutorial series in Swift 5.
So without further ado let's jump into today's lesson.
Okay we left off by
initializing cloud fire store in our Xcode project and we have just started
adding data, well we basically didn't add any data but that's what the
documentation suggests but before we do that let me just take this video session
and talk about and let me just show you about managing cloud fire store with the
firebase console because yeah you first need to get accustomed to the firebase
console so you can know what is going on when you actually do add data or read
data or acquire data. So that is one important thing and in the meantime I
will discuss with you what are those collection and documents and data in the
document and some awesome tips on how you can set up your data or maybe manage
your data. So go ahead and go to your docs and managed cloud fire store with
the firebase console is what you want to open up and you can simply go and skim
through this quite short documentation but it's essential. If you don't want to,
you don't have to we will cover almost everything in here. So what we are going
to do is view, add, edit, not delete data we will have a separate portion of this
master course on only focusing on deleting data. We are going to create an
update cloud fire store. Security rules again later on because yeah that is a
whole lot of section and I don't really saw any useful tutorials
on the net so I will deep dive into that too. I will show you where you can
manage indexes and maybe monitor usage. So basically what you need to learn from
this tutorial is how to view add added and delete data but in the firestore
console, okay. So let's jump right into our database.
If you already haven't done so go ahead and click the database so it may load up and
of course if you are going to presented these empty database and as you can see
we are starting off with this add collection button so let's do that.
Let's create a basic usage of this sort of tutorials is to create users profile and
I will just briefly start off with that and then I will show you how I do it in
production code. So first of all let's just add in here. So that is how you just
simply add yeah the example collection users would contain a unique
document for each user. So let's do that. Let's add in users here and let's click
on next and let's see we can create a document ID or we could add in an
AutoID. I prefer adding AutoID, again this will not be the case when this database
is connected to your app but it is an awesome way to create some data
structures or you can imagine and visualize what your data would look like.
So let's add in here field like maybe name not UID, name and it will be
a string and I will write it Alex and let's add in here another one let say language
choice that is Swift and let's save this, okay. Let's save this
and you will see that we have a users collection, we have a document in that
users collection and under that document we have some fields basically the
document data and these are key value pairs so language and name is are the
keys and values are Swift and Alex. So let's add in another document. So add
another document. Let's generate an audio ID and for the field again you have to
add in here again a name and the name let it be Tom and let's add
another field language and the language will be ObjC, okay. Let's save it.
Now you can see that we have two users with UIDs and both have language and
name associated to them, okay. Let's add in a third one so I can show you how you
can basically delete so we still have this too. So let's create an autoID here,
name let's add in here Toby and language again Objective C. Let's click on save.
There we go. So how do we actually add it first of all this name so just click on
this pencil icon and add it field let's say Toby let's say John would be a great name for
this user and as you can see it highlighted it bumped up a little bit
with red these fields like the users UID and the name and John key value pair so
we know that he this has been changed. N ow if you do make a change on your
client side this way and you are opened to this fields then you will see again
in red the changes that appear, okay. Now let's delete this language it's
pretty simple, click on the trash can icon delete field. Do you want to delete this?
Yes I do you want to delete it, okay. Now how do you basically delete all of
this users? Well you can delete the document or you can delete all of the
document fields if you wanted to but let's go ahead and delete the whole
document okay and confirm by start deleting and that is it we have deleted
all of that document. Now how do we delete all of these users? Well let me
just go in there and as you can see we have a delete collection. Again these are
deer here will be our collections and here documents inside that collection so
that is why here we could delete all the documents or one document that we were
in and now we can delete this collection. So let's do that.
And because documents are just a small part of collections and collections are
what are basically larger sets of documents we need to confirm by typing
in users here. So let's delete that and we are off to a blank page again. Now why
did I delete all of this? Well basically I deleted it because I want you to show
you how I do all of these structures well this basically of structure in production code
and first thing that we have to realize is that even after we build this app or
your app that you are working on you are going to go to production mode and in
the meantime you are going to develop further your application. So what that
means in perspective to the database is that while all the users are
using your app in production you still need to have some development data. So for
that I'm going to create two separate so-called branches of the database and
well basically they are two collections on the root of our database. So I would
just name this dev and let's see here let's add a document ID but I don't want
to have here like with Auto IDs like users or something like it it doesn't
really make sense so a document ID will be dev again because I want to have
again sets of collections. So let's add that in there and let's save. There we go.
And there we go we have a dev collection and a dev document. Next up is the
production so when we just name this collection prod and have the document ID
as prod and save that. So now when I want to write or read from the
development branch I just append this dev collection
dash document dev and then we have our collections here and fields. If I want to
choose to work on the production and that is what we have to do when we
basically launch our app on the App Store and I will talk about environments
in the separate tutorial series after we finish with this one on the cloud fire
store. Make sure to subscribe to the channel if you already haven't done so
so you can check that out later on. What you need to know now is that we have
development environment and the production environment and we can safely
work on new features on the development environment and if we can just simply
delete them. So this doesn't affect the actual app on the App Store. So let's add
a collection here and I will name these users.
So now that we have this users collection here let's add in some users
and I will add some private data and some public data to the users. So let's
just create that and we will see what we will add that there. So let's add in here
a document and I will select auto ID and yeah basically that's it let's save
now and now let's add a collection and let's name this private data. There we go.
Let's click on next and let's add in here some fields. Let's say now name
rather yeah it's not the name let's say card.
Let's have here 242 and so on it doesn't really matter and say they have
a card number here and it's a string so let's save that in there. So as you can
see here we have our private data and we have an auto ID here and we added a
field. Now let's add a new one and that is rather yet let's just delete this I
believe this needed to be added here but under private data I want to add this
card right here. So let's add a document here and just cancel this out yep sorry
about that we need to have this named as private data too as according to the
dev /dev that we did earlier. So let's add a new document here and I will name
this private data and add in here card 4242.
That would be enough okay and let's save that and now let's delete and this one again
you will see how to delete document, start this delete. There we go. So here we
have our private data, awesome and now we want to create some public data, public
data. There we go. Let's click on next and I believe we need to create something
here. So let's see let's add in here some public data, okay. Let it be name we call
this Alex let's add in here like age 36 and let's see here let's let's change
this to a number so 36 and let's add a timestamp here. So let's say time stamp
or I believe that shouldn't be a capital S stamp so we can add a date. So let's
see let's set it to meet at 12 and the time should be that is okay. So I'm
just going to query according to day. So let's save that and
there we go here we have our age name and so on. Now if you would want to
search throw documents you could order them by fields ascending descending and
as a condition here it mainly I would choose the timestamp and descending and
apply to it so all of this data would be there but of course because this is a
sub collection it doesn't really make sense because there will be only one
public data for quiring according to our time stamp we would need to have
a group collection query that we will talk about in a later episode. So that is
also available through code so yeah you could do this just be aware that it's
here that you can we just clear all of this, okay. Now let's take a look at some
other tabs here that is the rules we will talk about the database rules in a
separate section into several videos as you can see currently it is not safe
this, this database is not safe because everyone can read or write to it.
We will change that later on. Indexes, well we when we will query through our app we
will see what those indexes are and of course you could create them here but
it's much easier when you just create a query run your app through the simulator
for example and then you will get a link in the log and you just paste it in here
and create the index automatically and finally you can take a look at this
usage. Well you can take a look at your reads, writes and deletes and yeah that
is basically it and in the next video we are going to add some data to the
database within our Xcode project. Now I hope you enjoyed this video if you did
go ahead and give it a thumbs up, subscribe to the channel and hit that
notification bell to get notified of the next video. Now if you have any questions
regarding the firebase database dashboard go ahead and comment down
below I try to answer all of your questions as soon as possible and as
usual I will see you in the next one.