Firestore - batch.add is not a function

前端 未结 6 1142
滥情空心
滥情空心 2020-12-24 10:31

The documentation for Firestore batch writes lists only set(), update() and delete() as permitted operations.

Is there no way

6条回答
  •  醉酒成梦
    2020-12-24 11:27

    Lets assume that you have list of cities and you want to write them in batch.

     final CityList = FirebaseFirestore.instance.collection('cities')
     WriteBatch batch = FirebaseFirestore.instance.batch();
     for(CityList city in cities) {
        final newShoppingItem = ShoppingList.doc();
        batch.set(newShoppingItem, {
      'name': city.name,
      'createdAt': DateTime
          .now()
          .millisecondsSinceEpoch
    });
    }
     batch.commit();
    

提交回复
热议问题