How to delete all documents in collection in Fires

2019-08-21 04:01发布

This question already has an answer here:

I need to delete all documents in collection by clicking a button. But Firestore guide doesn't say how to delete ALL the files.

For example.

          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) {


// ...
                    }

This is part of my MainActivity file.

When adding a file, it pushes info to Firestore

But I also need to delete files(all)

P.S I always have less than 9 files in collection

P.P.S I've googled it, nothing found.

1条回答
太酷不给撩
2楼-- · 2019-08-21 05:04

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.

查看更多
登录 后发表回答