How to update a specific node from a Firebase data

2020-03-31 08:43发布

I have a relative simple Firebase database which looks like this:

enter image description here

How can i update the Room1 node? If i use this code, in stead of updating that node, it adds another one, with the new name, Room2.

databaseReference = FirebaseDatabase.getInstance().getReference().child("Rooms");
Query updateQuery = databaseReference.child(Room1).orderByKey().equalTo(Room1);
updateQuery.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        dataSnapshot.getRef().getParent().child("Room2").setValue("");
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {}
    });

Thanks in advance!

1条回答
贼婆χ
2楼-- · 2020-03-31 08:53
databaseReference = FirebaseDatabase.getInstance().getReference().child("Rooms").child(Room1);
databaseReference.setValue()

with whatever new value you want in the setValue() parentheses

查看更多
登录 后发表回答