laxminarayan1998
laxminarayan1998

Reputation: 1167

How delete the particular child of child in firebase realtime database?

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.

Upvotes: 1

Views: 147

Answers (1)

dc.boy
dc.boy

Reputation: 55

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());
        }
    });

Upvotes: 2

Related Questions