How can i update my information in different location? Android Firebase

荒凉一梦 提交于 2019-12-24 19:26:38

问题


Click this to see Firebase Data Structure

I want to update my information (firstname, middlename, lastname) which is in a different location. I'm updating my information using student account. It only update under student but I don't know how to update it under teacher. If I update my first name, middle name, last name, I want my first name, middle name, and last name update also under the two section under the class. Please help me.


回答1:


To update a record in a Firebase database, you can use setValue() method directly on the reference. Assuming that teacher is the direct child of the Firebase root, you can use this code:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference firstNameRef = rootRef.child("teacher").child(teacherId).child("class").child(classId).child("Listofstudents").child(listId).child("firstname");
firstNameRef.setValue("New Name");

In which teacherId, classId and listId are those random generated keys that i see in your database.

If you want to update the same data, in a different location, just add another reference to desired location and use the same setValue() method.

Hope it helps.



来源:https://stackoverflow.com/questions/44755198/how-can-i-update-my-information-in-different-location-android-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!