want to create a subcollection in document in firebase when user sign up to app in react native its children subcollection created

want to add a subcollection when the user signs up to the app a subcollection is created to its document which contains its children.
here is my code:

    try {
    await firebase.auth().createUserWithEmailAndPassword(email, password);
    const currentUser = firebase.auth().currentUser;

    const db = firebase.firestore();
    db.collection("users")
      .doc(currentUser.uid)
      .set({
        email: currentUser.email,
        lastName: lastName,
        firstName: firstName,
        
      }).collection('users').doc(currentUser.uid).collection("recipient").add({name:"test", age:"25" }).then((data) => {
        console.log(data.id);
        console.log("Document has added")
    }).catch((err) => {
        console.log(err)
    })
    
  } catch (err) {
    alert("There is something wrong!!!!" + err.message.toString());
  }
}

Leave a Comment