【发布时间】:2018-10-17 18:26:37
【问题描述】:
我需要有关 Firestore 的帮助。我有一个 AllUsers 数据集合,包含每个用户信息的用户 ID 文档。我想检查用户名是否已经存在; // “那个用户名已经存在”。我该怎么做?
` setupBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final String user_name = setupName.getText().toString();
Map<String, Object> commentsMap = new HashMap<>();
commentsMap.put("user_id", user_id);
commentsMap.put("timestamp", FieldValue.serverTimestamp());
commentsMap.put("user_name",user_name);
firebaseFirestore.collection("AllUsers").document(user_id).set(commentsMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Intent asda=new Intent(getApplicationContext(),MainActivity.class);
startActivity(asda);
finish();
}
}
});
`
【问题讨论】:
-
你得到了用户名,所以我想将用户名与数据库中保存的用户名进行比较并不难。顺便说一句,看起来重复。
-
我做不到,请帮帮我。
-
需要查看firebase firestore的结构。你也会添加结构吗?作为图像或其他东西。
标签: java android firebase google-cloud-firestore