Jadenkun
Jadenkun

Reputation: 327

Removing all children of a node while keeping a reference to the parent in Firebase

I have the following structure in Firebase (this is but a small sample of a larger structure):

enter image description here

I'd like to be able to remove all the children of employees node and keep the reference to it. I noticed that if I remove all the children of a node, the parent gets removed as well.

Something like: (After all children are removed)

enter image description here

Is there any way to keep the reference?

Upvotes: 0

Views: 224

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

You can do the following:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("employees").removeValue();

This will remove the whole node, then you can do:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("employees").setValue(0);

Upvotes: 1

Related Questions