Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
How to add new collection to existing document React v18, Firebasev9

Creating user:

  const register=async()=>{
    try{
    const user = await createUserWithEmailAndPassword(auth, registerEmail, registerPassword)
    const newUser = await addDoc(collection(db, "Users"), {
        email:registerEmail
      });
    setEmail(newUser.email) 
    navigate("/home");
    }catch(error) {
      console.log(error.message);
    }
  }

I tried to store email to match it with firestore user data email

Below is other component where I try to add new collection to specific user, but fail to do so

const createAnime = async () => {

const addAnime= await addDoc(collection(db,"Users",user.id,"anime"),{
        title,genre,numb,comment,rating,aid
      })
  }

I've tried various solutions. The goal is to add (title, genre, number, etc.) as separate documents to the user created. I fail to match the data from auth user to the same user data created in Direstore.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are using addDoc() when adding user's document to Firestore that generates a random document ID but then trying to add a sub-collection to document with user's UID (which probably doesn't even exist). Instead set the document ID to user's UID at first place as shown below:

const register = async () => {
  try {
    const { user } = await createUserWithEmailAndPassword(auth, registerEmail, registerPassword)
    
    const newUser = await setDoc(doc(db, "Users", user.uid), {
      email: registerEmail
    });
    
    setEmail(registerEmail)
    navigate("/home");
  } catch (error) {
    console.log(error.message);
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda