Skip to content Skip to sidebar Skip to footer

How To Delete A Specific Child From Firebase (java)?

I want to delete only the 1st child (L7jrJ6DtQWrmZsC4zvT) from Firebase database with an option in an Android app. I searched several places and could not find it. You only have on

Solution 1:

To delete a single object you can use removeValue() method directly on the reference like this:

DatabaseReferencerootRef= FirebaseDatabase.getInstance().getReference();
rootRef.child("calendario").child("-L7jrJ6DtQWrmZsC4zvT").removeValue();

Solution 2:

If i understood you correctly, you have the key of the child you want to remove and this child has no parent. so you can just use the single event listener like this -

val ref = FirebaseDatabase.getInstance().reference
        val applesQuery = ref.child("L7jrJ6DtQWrmZsC4zvT")
        applesQuery.addListenerForSingleValueEvent(
                object : ValueEventListener {
                    overridefunonDataChange(dataSnapshot: DataSnapshot) {
                        dataSnapshot.ref.removeValue()
                    }
                    overridefunonCancelled(databaseError: DatabaseError) {
                        Log.e("frgrgr", "onCancelled", databaseError.toException())
                    }
                })

this should work, let me know otherwise.

Post a Comment for "How To Delete A Specific Child From Firebase (java)?"