【发布时间】:2018-02-22 15:44:46
【问题描述】:
我有一个活动,在用户创建帐户(身份验证)后,它会自动在 FireStore 中的用户文档中放置 complete_profile=true。为了给你更多的视角,这是我的 Firestore 的样子:
users <-- Collection
|
A8as7f9aKsrYas12l7 <--- User's ID/Document
|
complete_profile: "true" <-- Field
现在,我有另一个页面,名为 completeprofileactivity。它询问用户的姓名。之后,我想在我的用户数据name: "sample name" 中添加另一个字段。问题是添加名称后,complete_profile 消失了:
users
|
A8as7f9aKsrYas12l7
|
name: "sample name" <-- replaced?
当我再次使用同一个用户重新创建一个新帐户时,它应该添加complete_profile 对吗?所以我将同时拥有name 和complete_profile。但相反,我又得到了这个:
users
|
A8as7f9aKsrYas12l7
|
complete_profile: "true" <-- it replaced the "name" again
我的完整个人资料有此代码:
Boolean userdoComplete = true;
String str_userid = mAuth.getCurrentUser().getUid();
Map<String, String> user_map = new HashMap<>();
user_map.put("complete_profile",userdoComplete.toString());
mFirestore.collection("users").document(str_userid).set(user_map).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
//Registered Successfully
//Intent to Main Activity
Intent goMain = new Intent(SignUpActivity.this, MainActivity.class);
startActivity(goMain);
} else {
}
}
});
以及添加名称:
String str_userid = mAuth.getCurrentUser().getUid();
Map<String, String> specialMap = new HashMap<>();
specialMap.put("name", name);
mFireStore.collection("users").document(str_userid).set(specialMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
//All is Successful - Proceed
Toast.makeText(AddSpecialActivity.this, "Successful!", Toast.LENGTH_SHORT).show();
} else {
//FireStore Error
Toast.makeText(AddSpecialActivity.this, "There was an Error. Please Try Again.", Toast.LENGTH_LONG).show();
}
}
});
我不明白为什么一个人总是替换另一个人。它应该同时添加complete_profile 和name。
【问题讨论】:
标签: android firebase firebase-realtime-database google-cloud-firestore