0

I have created a chat app. In the app there is a collection named Chat and in it there are documents. Each document is a message that was sent and it contains fields such as Message, SentTime, IsButton.

Once something happens in the app (someone clicks a button), I had like to change in all of my documents at that chat the value of IsButton from False to True.

The data looks as follows:

enter image description here

Is there a way to change all of the Field values in one hit instead of using a loop?

I saw there is something called Batch however I'm not sure if it is limited to a maximum 500 updates.

Thank you

Community
  • 1
  • 1
Ben
  • 1,737
  • 2
  • 30
  • 61
  • There is no way to update multiple documents with a single API call. You have to call out each document ID individually, and you can use a batch if you wish. – Doug Stevenson Apr 05 '20 at 17:59

1 Answers1

0

The two approaches you've found are pretty much the way to update a bunch of document.

You can:

  • either update each document individually, which is not nearly as slow as you may think.
  • or you can update the documents in one of more batches.

Having to update many documents with the same value may be a sign that you should reconsider your data structure. For example, maybe you can store the IsButton in a single, separate document that all clients then read/listen to.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807