0

I want to update a variable after click the button. This is my collection in firestore, and this is my variable what i want to update. Firestore Collection

That variable "bagAmount", after click I want all of them to be equal to 1. I know how update one of then, past the ID of my document, like that:

this.firestore.doc("lunch/" + this.bagIndex).update({bagAmount: 1});

But how i update all? Thanks!

  • You have to query for all the documents, iterate the results, and update each document individually. There is no equivalent of a SQL "UPDATE WHERE" statement that updates multiple documents at once. – Doug Stevenson Sep 20 '22 at 14:41

1 Answers1

0

Several methods exist for writing data to Cloud Firestore:

  • By specifically mentioning a document identifier, set the data for the document within a collection. Add a fresh document to a repository.

  • In this instance, the document identifier is generated automatically by Cloud Firestore.

  • Create a blank document with a randomly generated identification, then fill it with information afterward.