Firestore批量查询更新不适合我

时间:2019-01-12 17:26:51

标签: firebase flutter google-cloud-firestore

这里我有一个代码来更新我的firestore数据库,这里'm'是文档ID的列表,'a'是数字的列表,'b'是布尔值的列表,所有列表的长度都是相同。

如果以下方法有误,请给我一个示例,以一批更新50个文档

select e.name
from (select 1 as id union all
      select 1 as id union all
      select 1 as id union all
      select 1 as id union all
      select 2 as id union all
      select 2 as id union all
      select 2 as id
     ) i left join
     events e
     on e.id = i.id;

我不知道为什么它没有更新我有一个50个文档ID的列表,IAM正在尝试 仅更新列表(由用户选择)中的某些文档。即通过循环检查使用B [i]时的条件的更新,此处B是布尔值列表,因此仅将需要的dcouments添加到batch.ausume a [i ] +1是整数

如果上述方法有误,请举一个例子,说明如何一次更新50个文档

1 个答案:

答案 0 :(得分:0)

哦!没有上面的代码是正确的,但我使用了布尔编码,而当它为false时,总循环终止,而是替换逻辑条件的条件,并在while循环中使用布尔条件tha将设置ur 码     `void onpressed()异步{

                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()   ;           });
                                    }`