‫In this video, we will learn how to create and write data inside Cloud Firestore.
‫We can see on this page we have the collections and when we insert data, we will see the documents.
‫Also, we learned that the collection is a set and a group of documents.
‫Let's start creating and initialize an instance of cloud firestore.
‫Before we begin, as I told you, I have added the dependency for Fire Firebase Firestore.
‫Also, you can specify.
‫The ID and you should specify the Google services and at the project level you should add the build
‫scripts.
‫Now.
‫Let's go back here.
‫I need to specify and access a cloud firestore instance from my activity.
‫Val db equal Firebase dot Firestore.
‫If I click on alt plus enter, I will import it.
‫How I know that and how Android studio knows what Firebase and Firestore link and what is the reference
‫to that?
‫We need to add a file here at the project level.
‫This is inside the app folder and this is called Google Services Json.
‫And we've added before in the previous section to this application.
‫So please go back to the previous section in order to learn about how to add these files to and configure
‫Firebase for our Android applications.
‫This is how we initialize cloud firestore initialize.
‫Fire store.
‫Now let me create a collection.
‫Creating a collection.
‫Of users.
‫Okay.
‫As I told you in the presentation, I'm going to create a.
‫A collection called Users that contains many users.
‫And the users are documents.
‫Let's start by this collection.
‫Users underscore collection.
‫I will show you this.
‫This naming.
‫I prefer using this naming in order to tell and understand that users underscore collection is acting
‫as a collection in my Firestore DB dot collection and I will create a new collection called users.
‫Here I am setting the collection path.
‫You can see how Firebase products are very simple and how they are.
‫A very, very simple and very like easy to understand and to use.
‫With one line, I can create a collection and I can create a document and save these documents inside
‫the collection.
‫So here I need to create a creating document.
‫Documents.
‫I will create two documents for two users.
‫Okay.
‫I will start with user one equal.
‫Hash map of I need a collection from Kotlin in order to start adding the hash map.
‫Uh, hash map key value pairs for my document.
‫I will start with name to.
‫Jack.
‫You can set to which I'm linking the name the key to value Jack age or last name?
‫To.
‫Richer.
‫Remember, guys, I am creating this hierarchy.
‫This is the name of my collection.
‫This is the name of the first document and this is the name of the second document.
‫And each document contains the data first, last and born.
‫Again.
‫I need this.
‫Comma.
‫And born.
‫219.
‫92.
‫This is the first document How to add the document to.
‫The collection.
‫Adding.
‫Documents to collection.
‫It's very simple.
‫Here I am specifying users collection.
‫It's similar to the to the collections framework in Kotlin.
‫Here I will set the document.
‫Document.
‫User one.
‫Creating the document and dot set.
‫This is the method that I use to upload this document into this document node.
‫Inside this collection.
‫In firestorm.
‫I will set user one.
‫So I am telling that I need to create a collection of name users and add the first document called user
‫one.
‫Want to set the values and refer to it.
‫I am referring by this map.
‫This is how I create document and how we assign and add documents to collections.
‫I will create another document called user two.
‫Name would be John.
‫Last name is Travolta and 1982.
‫I will add this collection.
‫To this collection.
‫I will add this document.
‫User to.
‫Okay.
‫So the first step is to initialize Firestore.
‫The second step is to create the collection.
‫The third step is to create the documents.
‫And the fourth step is to add the documents to the collection.
‫Let me run our project.
‫And here we go.
‫Let's start.
‫Let's wait for starting the emulator.
‫And installing the app.
‫Here we go.
‫Opening the application.
‫We need to wait.
‫If I refresh this page.
‫I think the error is we are missing some rules and the permissions.
‫Let me go to Android manifest and here I need to add users permission internet.
‫And also I need to change the rules on Firebase Firestore.
‫Allow read right here from false to true.
‫Click, publish and.
‫Go back to the data.
‫Now let's run our application again.
‫This is our Firestore application.
‫It's running and let's wait or refresh the page.
‫Let me make a refresh.
‫And here we go.
‫You can see the collection called Users and you can see I'm opening it.
‫This is the collection browser or the the folder called users.
‫Think about it like a folder and you can see I have a document user one and user two.
‫So congratulations guys.
‫Here we learned how to send and create collections and documents into Cloud Firestore using our Android
‫applications.