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

344
Vistas
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 Respuestas
Responde la pregunta

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 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