Reputation: 193
I am trying to remove a simple value on my firebase tree like this:
To do that, I need to get the current userId, the name of the clicked group and the user that was clicked. I get all that information, and then I do this to delete:
id = auth.getCurrentUser().getUid();
group = getIntent().getStringExtra("group");
database = FirebaseDatabase.getInstance();
myRef = database.getReference().child("Users");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myRef.child(id).child("FriendLists").child(group).child(user.getId()).removeValue();
usersList.remove(user);
mAdapter.notifyDataSetChanged();
}
});
The thing is, removeValue deletes all the node beginning at FriendLists, all the info and even the FriendLists dissapaear :S, any info, any help?
Upvotes: 0
Views: 635
Reputation: 598740
Firebase automatically creates a path when you store a value at that path. It also removes a path if there is no longer any value under that path. So when you remove the last friend from a group, the group will also disappear. And then it's the last group, then the FriendsList
parent also disappears.
Also see:
Upvotes: 2