This isn't a duplicate because I did not find any question or solution for writing more than 500 documents using batches in FLUTTER. I've seen answers for this in other frameworks or languages but I can't understand how to implement this in flutter. I need to update documents in my collections using batch write but a batched write can only contain 500 operations. So how do I write more than 500 documents to firestore? I've seen iterating as one of the solution but how do I implement that in flutter?
This is how I am performing single batch write:
Future<void> batchUpdate() {
WriteBatch batch = FirebaseFirestore.instance.batch();
return users
.get()
.then((snapshot) {
for (DocumentSnapshot document in snapshot.docs) {
document.reference.update(
{
'totalScore': 0,
},
);
}
return batch.commit();
})
.then((value) => ScaffoldMessenger.of(context).showSnackBar(snackBar))
.catchError(
(error) => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(error),
),
),
);
}