Select Page

Original & Concise Bullet Point Briefs

Firestore Commit Batch Operation | Write Using batch().set

Making Batch Operations Easier with Firebase Firestore

  • Firebase batch comment allows users to commit batches of operations at the same time
  • Firebase firestore is necessary as it provides a global variable to access from anywhere
  • Using Firebase’s set function, one can create a collection, document and fields for that document
  • One example given is creating a quiz paper collection and a user email ID document with sub collections and documents
  • Committing batches of operations is easy, simply by getting the Firebase firestore instance, creating a batch object and calling the set method.

Checklist for Document Preparation: What to Know Before You Begin

  • 1. Ensure that at least one document is available
  • 2. Specify the fields required for that particular document.

Original & Concise Bullet Point Briefs

With VidCatter’s AI technology, you can get original briefs in easy-to-read bullet points within seconds. Our platform is also highly customizable, making it perfect for students, executives, and anyone who needs to extract important information from video or audio content quickly.

  • Scroll through to check it out for yourself!
  • Original summaries that highlight the key points of your content
  • Customizable to fit your specific needs
  • AI-powered technology that ensures accuracy and comprehensiveness
  • Scroll through to check it out for yourself!
  • Original summaries that highlight the key points of your content
  • Customizable to fit your specific needs
  • AI-powered technology that ensures accuracy and comprehensiveness

Unlock the Power of Efficiency: Get Briefed, Don’t Skim or Watch!

Experience the power of instant video insights with VidCatter! Don’t waste valuable time watching lengthy videos. Our AI-powered platform generates concise summaries that let you read, not watch. Stay informed, save time, and extract key information effortlessly.

hello everyone assalamualaikum here we'll take a look how to use Firebase batch commenting or  how to commit batches of operation at the same time so that you can create  collections document sub collections documents and a lot of fills together  now over here we'll see that this is a method and this method gets called from the UI from a button  click and as it gets called first here we get the Firebase reference for firestore now fi refers to  the Firebase firestore instance now I put it in a separate file you can put it anywhere you want  and once I have this object reference fi now I can access the method which is called batch now I save  it in a variable called a batch you can name it anything you want now since I'm going to submit a  batch operation to Firebase and it has to do with user so first here I check if I have a user or not  if the user is null then we just return but in your case you might not have a user you could do  anything with the Firebase database so you may use this you may skip this it doesn't really matter  now right after this we see this batch object the one we created at the top and it has a  function which is called a set now inside set actually if you hover over on it you will see  that you have to have a document reference at the end and there are some data options  now over here first you have to get the collection reference so user FR actually at collection name  as you can see here so it's a Firebase collection name so once again we are getting it from fi  because f i I created a global variable so we can access it from anywhere so using this  fi we get a collection of users name is users well of course if this collection doesn't exist  flateral created automatically so over here we get users collection right and for that user we  have a document now if the document doesn't exist it will create one now in my case this is dynamic  because user could be anyone so whoever the user is whatever the email address we go ahead and  save it and create a document for you it could be hard-coded or dynamic as well or any other name  and then we create another hard-coded collection for this document so actually  it becomes a sub collection now for this sub collection we create another document  so here we have collection document sub collection sub documents like that  now in your case you might just have a document and then you do rest of the things anyway so after  this document here we create some Fields What fields we create we create points correct count  paper ID and time now these are some Dynamic data so in your case you can use any kind of  data you want it doesn't matter so the idea is if we want to create batch operation or submit  or commit batch operation we have to create a batch object from Firebase firestore and then  for that object we have to call the set function Now set function has to take at least one document  or as sub collection sub collection documents sub-documents and some related fields  now in your case you might just have one document and then you can go ahead and create  some fills so this is the first batch of operation that we want to create  then we have another one over here once again this is also a collection  name if you click on this you will see that this is also a collection namenow for that collection we get documents and you create a sub collection and then we have  another document that we create and after that actually we go ahead and create some new fields  for this collection and at the end this is the syntax that we should run which is called batch  dot Comet now with this we'll create a lot of Collections and subcollection documents and sub  documents at the same time now we are going to do it in real world so let's take a look  with the real example now here I have only one collection which is called quiz papers  now if we create this batch operation over here we'll see that we have  if we do this batch operation over here we'll see that we'll have user collection  the letter pepper and related email documents and the quiz paper documents the same over here  now let's go ahead and submit a batch operation so I'm going to go ahead very quickly  and I'm going to submit it over hereso this is the place if I go ahead and submit and we'll see that  over here we'll have new Collections and that would happen because of batch operation  now if we do do that one at the bottom actually we'll see that there is a print message okay  which means that it ran over here now let's go ahead and submit this  okay well it happened very quickly now we do see that here we have this batch committing  the printing message and after that we navigate to home where we see the Home Route great now  at the back end we're gonna go ahead and check it so we're going to refresh our database over here  so it's a refreshing and we do see that over here we have quiz paper ladder board the one we have  seen over here this is the letter Bird collection and we also have users collection so letter letter  Bird collection has document scores and the sub documents and these are the fields that we createdthis is the fields that we created as you can see over here points correct  count paper ID and as well as we also have created a user document  for that user document we have sub collections over here as you can see let's take a lookso here we have user email IDs document and there's the sub collection that we have seen  and more documents and sub collections so while committing a batch operation may sound scary  but actually it's pretty easy all you need to do get a five-star instance and get a batch object  and then call this set method for that one and make sure that at  least you have one document and for that document you have this fields