I need help with Firestore. I have a AllUsers data collection, user id-documents with each user information. I want to check if username already exists; // "That username already exists". How do I do it?
` 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();
}
}
});
`