Antonio Costa
Antonio Costa

Reputation: 193

Firebase removeValue removes parent instead of single value

I am trying to remove a simple value on my firebase tree like this:

example

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

Answers (1)

Frank van Puffelen
Frank van Puffelen

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

Related Questions