如何使用Flutter删除Firestore中集合中的所有文档 [英] How to Delete all documents in collection in Firestore with Flutter
本文介绍了如何使用Flutter删除Firestore中集合中的所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Firestore数据库.我的项目插件:
I have a firestore database. My project plugins:
cloud_firestore:^ 0.7.4 firebase_storage:^ 1.0.1
cloud_firestore: ^0.7.4 firebase_storage: ^1.0.1
这有一个包含多个文档的邮件"集合. 我需要删除邮件集中的所有文档.但是此代码失败:
This have a collection "messages" with a multiple documents. I need to delete all documents in the messages collection. But this code fail:
Firestore.instance.collection('messages').delete();
但删除未定义
正确的语法如何?
推荐答案
啊.第一个答案是几乎是正确的.该问题与dart中的map方法及其与Futures的工作方式有关.无论如何,尝试像这样使用for循环,您应该会很好:
Ah. The first answer is almost correct. The issue has to do with the map method in dart and how it works with Futures. Anyway, try using a for loop instead like so and you should be good:
firestore.collection('messages').getDocuments().then((snapshot) {
for (DocumentSnapshot ds in snapshot.documents){
ds.reference.delete();
});
});
这篇关于如何使用Flutter删除Firestore中集合中的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文