‫We created the references for both collection and document.
‫Now let's move to learn how to execute the operations.
‫Save, delete, update and read in Firebase Firestore database.
‫I'll start with save.
‫So I'll create a new method here I'll name it as Save data to new document.
‫I'll create a string name equals to name it which is the edit text dot.
‫Get text dot to string.
‫I'll get the data from the edit text name and the edit text email.
‫And when the users click on the save data, it will be sent it to the database.
‫So for that I'll create another string called email equals to email dot get text dot to string.
‫I need to store these variables in a friend object.
‫I'll create friend.
‫Friend equals to new friend.
‫Passing name and email.
‫Since I'm using custom objects, I need to deal with custom objects in the database.
‫So I'll show you guys.
‫Please pay attention.
‫I'll use a method from the collection reference object called add, and here I need to pass the friend.
‫The collection reference represents a reference to a specific collection within your Firebase database.
‫And if we scroll up we can see this collection reference represents the users dot add.
‫This method is called on collection reference to add a new document to the specified collection.
‫Friend is the context of an object represents the data you want to store in the new document.
‫This data.
‫This friend object will be serialized and stored in the new document.
‫So this is how we add a new document to a collection.
‫Also, you can handle the success and the failure of this operation by adding here dot add on success
‫listener, new on success listener.
‫And you can see the on success method is overriding.
‫The document has been successfully added and the document reference contains its ID.
‫And also if you can check the document reference to get the ID, you can use string document id.id equals
‫to document reference, which is the parameter from here dot get id.
‫So if the addition of this friend object is successfully inserted and added in the database, the on
‫success listener will be called and you can obtain document reference and store it inside doc ID string
‫variable save dot set on click listener and I'll call this method.
‫There is a problem.
‫I missed the the manifest here to add the users permission.
‫Internet run again Jack.
‫Jack at gmail.com.
‫Click save.
‫Let's refresh our database and congratulations guys!
‫We created this users.
‫This is the collection and if you open it you can display this sub collection users.
‫This is the first user and this is the document.
‫This is the name the ID of the document.
‫And this is the key value pairs email and name.
‫Delete this document and I'll keep this user.
‫You can add more.
‫So I'll add John John at gmail.com.
‫Click on save data.
‫Refresh the database or without refreshing if you notice that it is added here.
‫So congratulations guys.
‫We learned how to save data how to insert data into Firebase Firestore or databases.