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

345
Visualizações
Firebase Firestore: create collection in collection

How to create a collection in collection like this:

    firestore().collection('users').doc(user.uid).collection("account").doc('doc-account').set({...});

How to do it ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your question is about how to create a subcollection named account under a root collection named users.

You just need to do exactly the way you have shown in your question, using the set() method on the doc-account DocumentReference: as soon a first document will be added under the account subcollection, this subcollection will exist.

Same effect if you use the add() method on the account subcollection, as follows:

firestore().collection('users').doc(user.uid).collection("account").add({...});

And you even don't need to have a users collection, i.e. having a document in the users collection. This last point is a bit surprising at first sight, let's explain it with an example:

Take a doc1 document under the col1 collection

col1/doc1/

and another one subDoc1 under the subCol1 (sub-)collection

col1/doc1/subCol1/subDoc1

Actually, from a technical perspective, these two documents are not at all relating to each other. They just share a part of their path but nothing else. This is why the subDoc1 document (and its parent subCol1 collection) can exist without the doc1 existing. One notable side effect of this is that if you delete a document, its sub-collection(s) still exist.

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