Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!