• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

database.collection("Users").document(userID).set(map)

Pd89

Lurker
Hello guys,

I'm really new here, hope someone could help.
I ve a problem apparently simple, but i'm going crazy to fix it!

So, as title saying, I'm trying to add a new document in my Cloud Firestone using this way:

private void saveOnFireCloud(String userID, String name, String email) {
String GeneratedID;
Map<String,Object> map = new HashMap<>();
map.put("id",userID);
map.put("name",name);
map.put("email",email);

database.collection("Users").document(userID).set(map)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@override
public void onComplete(@NonNull Task<Void> task) {

Toast.makeText(Register.this, "Data Inserted!", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Register.this, "Error Inserting Data!" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}

The document is created with success, BUT instead of create the document key with userID as i passed,
it generate a new random ID document key. I also tried to pass "TESTKEY" String instead of userID just for test purpouse but fails and generate again a random id... Anyone knows why?

PS: userID is the Auth Firebase ID, cause I want to link my new Document key to an existing user in Firebase Auth section! I think this is the right way, but not completely sure.
 
Back
Top Bottom