如何从Android删除Firestore中集合中的所有文档? [英] How to delete all documents in collection in Firestore from Android?
问题描述
我需要通过单击按钮来删除集合中的所有文档.但是Firestore指南并未说明如何删除所有文件.
I need to delete all documents in collection by clicking a button. But Firestore guide doesn't say how to delete ALL the files.
例如.
public void onClick(View view) {
// movieList.clear();
WriteBatch batch = db.batch();
Movie movie = new Movie(subj.getText().toString(), cab.getText().toString());
movieList.add(movie);
mAdapter.notifyDataSetChanged();
DocumentReference nycRef = db.collection("Users").document();
batch.set(nycRef, new Movie(subj.getText().toString(), cab.getText().toString()));
batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// ...
}
这是我的MainActivity文件的一部分.
This is part of my MainActivity file.
添加文件时,它将信息推送到Firestore
When adding a file, it pushes info to Firestore
但是我还需要删除文件(全部)
But I also need to delete files(all)
P.S我收藏的档案总是少于9个
P.S I always have less than 9 files in collection
P.P.S我已经用谷歌搜索了,没有发现.
P.P.S I've googled it, nothing found.
推荐答案
Firestore不提供任何API来删除集合中的所有文档.您要做的就是查询所有文档,收集所有ID,然后编写一些代码以迭代这些ID并删除所有ID.
Firestore doesn't provide any API to delete all documents in a collection. What you'll have to do is query for all the documents, collect all of their IDs, then write some code to iterate those IDs and delete all of them.
这篇关于如何从Android删除Firestore中集合中的所有文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!