I have a collection which has a subcollection.I do not want to delete the collection,but I want to delete all subcollections of a particular document(i.e.currentuser doc) when user kills the app.
I was doing something like below from client side using services.But then that only deletes the collection documents data,it does not delete the subcollection:
class onAppKilled: Service() {
private lateinit var mFirestore:FirebaseFirestore
private var mAuth: FirebaseAuth? = null
lateinit var currentUser: FirebaseUser
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onTaskRemoved(rootIntent: Intent?) {
mFirestore= FirebaseFirestore.getInstance()
mAuth = FirebaseAuth.getInstance()
currentUser= mAuth!!.currentUser!!
currentUser.delete().addOnCompleteListener(OnCompleteListener {task->
if(task.isSuccessful){
Toast.makeText(this@onAppKilled,"User Deleted", Toast.LENGTH_LONG).show()
}else{
Toast.makeText(this@onAppKilled,"User not deleted", Toast.LENGTH_LONG).show()
}
})
mFirestore.collection("AllUsers").document(SplitString(currentUser.email!!)).delete()
}
I read about using cloud functions for deleting subcollections.So i installed cloud functions with my app but now I am not sure how do I go about deleting the particular documents subcollection when the app is killed?