如何更改此代码以便更新当前用户而不是创建新用户?

时间:2018-05-15 19:32:07

标签: java android firebase firebase-realtime-database

如何更改此设置以便更新当前用户的详细信息而不是创建新用户?

          Userdatabase = FirebaseDatabase.getInstance();
          Userdatabaseref = Userdatabase.getReference().child("Threads 
           Users");            


          DatabaseReference CurrentUser = Userdatabaseref.child("Threads 
          Users");

            Map<String, String> userdata = new HashMap<>();

            userdata.put("userfirstname", Fname);
            userdata.put("userlastname", Sname);
            userdata.put("userdateofbirth", DOB);
            userdata.put("useraddress", Add);
            userdata.put("userpostcode", Ptd);
            userdata.put("usercardnumber", Cnumber);
            userdata.put("usercardexpirydate", Cdate);
            userdata.put("userccvnumber ", CCV);

            CurrentUser.setValue(userdata);
        }
    });

1 个答案:

答案 0 :(得分:0)

使用updateChildren

Userdatabase = FirebaseDatabase.getInstance();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
Userdatabaseref = Userdatabase.getReference().child("Threads 
           Users");            
DatabaseReference CurrentUser = Userdatabaseref.child("Threads 
          Users").child(firebaseAuth.getCurrentUser().getUid());
Map<String, Object> userdata = new HashMap<>();
userdata.put("userfirstname", Fname);
userdata.put("userlastname", Sname);
userdata.put("userdateofbirth", DOB);
userdata.put("useraddress", Add);
userdata.put("userpostcode", Ptd);
userdata.put("usercardnumber", Cnumber);
userdata.put("usercardexpirydate", Cdate);
userdata.put("userccvnumber ", CCV);

CurrentUser.updateChildren(userdata);