1

I want to delete the particular child of a child in firebase realtime database.

I have added a picture of my database.

I want to remove the highlighted child.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
laxminarayan1998
  • 838
  • 8
  • 13
  • You'll need to know enough about the node to delete to be able to find it in the database. If you do, you can either construct the path directly, or query for the node. See https://stackoverflow.com/questions/37390864/how-to-delete-from-firebase-realtime-database?rq=1 – Frank van Puffelen Sep 16 '19 at 10:21

1 Answers1

2

You can try this code.

 Query query =  myRef.child("Purchase_Request").orderByChild("Chimney_Purchase");

    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snap: dataSnapshot.getChildren()) {
                if(snap.getKey().equals("your_key")) {
                    snap.getRef().removeValue();
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "onCancelled", databaseError.toException());
        }
    });
dc.boy
  • 55
  • 9