Reputation: 549
here i have a code to update my firestore database here 'm' is a list of document id's,and 'a' is a list of numbers and 'b' is a list of boolean values , all the lenght of lists are same.
if below method is wrong please give me an example to updated 50 documents in one batch
void onpressed() async{
alert('updating');
WriteBatch batch= Firestore.instance.batch();
int i=0;
while(b[i]){
batch.updateData(Firestore.instance.collection("allstu").document("17csea").collection("17csea").document(m[i]), {"attendance": a[i]+1});
i++;
}
await batch.commit().then((value){
alert("update successful");
}
).catchError((err){
alert("Something went wrong try again");
});
}
i dont know why its not updating i have a list of 50 document ids and iam trying to update only some documents in a list(selected by user).that is update with loop checking the codintion of while using B[i] here B is list of boolean values so that only reuired dcouments are added to batch.ausume a[i]+1 is a integer
if above method is wrong please give me an example to updated 50 documents in one batch
Upvotes: 3
Views: 2512
Reputation: 549
oH ! no the above code is correct but i have used the boolean codition in while when it is false the total loop is terminating instead replace the condition whith anthor logical condition and use the boolean condition inside the while loop tha will set ur code `void onpressed() async{
WriteBatch batch= Firestore.instance.batch();
int i=0;
while(i<m.length){
if(b[i]){
batch.updateData(Firestore.instance.collection("allstu").document("17csea").collection("17csea").document(m[i]), {"attendance": a[i]+1});
print("success");}
i++;
}
batch.commit().then((value){
print("erorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
Navigator.of(context).pop();
}
).catchError((err){
print(err);
Navigator.of(context).pop() ; });
}`
Upvotes: 2