Advertisements

FS DB Deleting a complete collection

        //Getting instance
        FirebaseFirestore db = FirebaseFirestore.getInstance();


        //Getting Reference to "users" collection, calling get to retrieve data, adding a callback
        db.collection("users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                // Task complete
                if (task.isSuccessful()) {
                    //Task successful
                    //Getting each document one by one in that collection
                    for (QueryDocumentSnapshot documentSnapshot: task.getResult()){
                        //Performing the delete operation 
                        documentSnapshot.getReference().delete();
                    }
                }

            }
        });