0

I know im asking too many stupid question but please help me out if possible, so i am using this code to send data to firebase:

            try {
                const docRef = await addDoc(collection(db, "users"), {
                  owner_uid: authUser.user.uid,
                  username: username,
                  email: authUser.user.email,
                  profile_pic: await randomProfiles()
                });
                console.log("CREATED");
           

     this.props.phase(0);
                  } catch (e) {
                    console.log(e);
                  }
                } catch (error) {
                  console.log(error);
                }
              };

I cannot figure out how to set the doc id using this code. it was written by a friend. I read the documentation of firebase but i cant figure out how to implement this in to my code :

     db.collection("users")
      .doc(authUser.user.email)({
        owner_uid: authUser.user.uid,
        username: username,
        email: authUser.user.email
      })
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84

1 Answers1

1

In Firebase version 9, in order to specify the document id when adding a document do this:

const users = collection(db, "users")
await setDoc(doc(db, users, authUser.user.email), data);

Check documentation for more information.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
AyseAsude
  • 554
  • 4
  • 13