36

I have a number of child nodes in my firebase db and I want to delete only one child node.

Firebase firebase=new Firebase("..address..");

firebase.push().setValue(classObj);

//here classObj is a class object which has a getter and setter for an integer id

Now that I have pushed multiple objects I want to delete only one based on the id in the classObj

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Akhil
  • 511
  • 1
  • 8
  • 13

4 Answers4

81

To remove data:

firebase.child(id).removeValue();

You might do well to have a look at the Firebase documentation for Android btw, which covers this and many more topics.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
15

If you are using DatabaseReference for firebase

DatabaseReference dbNode = FirebaseDatabase.getInstance().getReference().getRoot().child("Node");

Here Node represents the child which you wish to delete

dbNode.setValue(null);

If you are using a dataSnapshot

i.e., while you are working on some data change events

dataSnapshot.getRef().setValue(null);
Rhox
  • 17
  • 8
1

To remove a Node or child node

private FirebaseDatabase database = FirebaseDatabase.getInstance();

database.getReference("root_node_name")
   .child("child_node_name")
   .removeValue();

To remove Sub-child node

database.getReference("root_node_name")
   .child("child_node_name")
   .child("sub_child_node_name")
   .removeValue();
0

You need to run this code:

 Firebase firebase=new Firebase(URL);
    firebase.child(id).removeValue();
Sunny Sultan
  • 1,090
  • 15
  • 20