Home > Net >  Firebase update collection very slow
Firebase update collection very slow

Time:07-10

I have collection "collection" in firebase and I need to update all documents. But with this code it is very slowly and I don't know why

  firebase.firestore().collection("collection").get().then(function (querySnapshot) {
         querySnapshot.forEach(function (doc) {
             doc.ref.update({
                 newValue: 'someValue'
             });
         });
     }).then(console.log('DONE'))

I tried to add after update all values 'then' block to see when it is done, but console log "DONE" shows befor values starts updating in firebase. And after some time 3-5sek i see in firebase result. It's update documents one by one and very slowly. I can see progress. And I have only 300 documents. What would be if I there would be thousands documents?

Maybe there is different way to update values and if so, then why this way is slow?

CodePudding user response:

3-5 seconds for reading and writing 300 documents doesn't sound bad at all.

You can try using a batched write, but there's no guarantee that will be faster.

  • Related