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

90
Vistas
Can I add A Firebase collection in a collection

I have a form that collects user information and favourite foods But when collecting favourite food I want the favourite Food collection to be a Child to the 'users' collection Likes:

const sendPosts = (e) => {

    e.preventDefault()
    db.collection("users").add({
    
    //here I add the user details
    name: "userName",
    lastName: "userLastName",
    
    //is it possible to also add a collection like this after "lastName"
    
    collection("favFood").add({
    favDrink: "userDrink",
    favDessert: "userDesert",
      })
    })
  }

is it possible to do it like that or is it impossible or there is a simple way?

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

0

Yes it is possible, since the add() method returns the DocumentReference of the newly created document.

db.collection("users").add({
    name: "userName",
    lastName: "userLastName"
})
.then(userDocRef => {
    userDocRef.collection("favFood").add({
        favDrink: "userDrink",
        favDessert: "userDesert",
    });
});

userDocRef.collection("favFood") declares the CollectionReference of the favFood subcollection of the newly created user document. See the doc.

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