1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Development' started by Pd89, Mar 26, 2021.

  1. Pd89

    Pd89 Lurker
    Thread Starter

    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.
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - database collection Users
  1. Pd89
    Replies:
    0
    Views:
    385
  2. AndiDroid2
    Replies:
    1
    Views:
    418
  3. denerex
    Replies:
    0
    Views:
    1,071
  4. Alex Ethridge
    Replies:
    0
    Views:
    280
  5. manjula1
    Replies:
    0
    Views:
    593
  6. FoxMulder
    Replies:
    0
    Views:
    536
  7. Cinemato
    Replies:
    0
    Views:
    610
  8. RamAy
    Replies:
    1
    Views:
    1,038
  9. arpan_de
    Replies:
    0
    Views:
    365
  10. Dilip Birajadar
    Replies:
    4
    Views:
    707

Share This Page

Loading...