Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda