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

318
Views
Firebase v9 - Get a Referentiated Document Content

I don't understand why I'm not finding this documentation anywhere.

But I have a collection called users in my Firebase Firestore project. Inside users there are three collections: companies, policies and stores.

In the collection policies I have one store field and one company field that are references to one of that user's store or company.

Ok so as far as now is fine. But now, I'm performing the next query:

const subcollectionSnapshot = await getDocs(collection(db, 'users', 'S3casIyXxdddEAaa1YJL6UjBXLy2', 'policies'));

And the response is the next one: enter image description here

But now... how can I get the company and store nested documents? How can I "populate" them in order to see their information and access their fields?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like the company and store fields are of type DocumentReference.

In that case you can get a DocumentSnapshot of each of them by calling getDoc() with the DocumentReference:

subcollectionSnapshot.docs.forEach((policyDoc) => {
  const companyRef = policyDoc.data()["company"];
  const companyDoc = await getDoc(companyRef);
  const storeRef = policyDoc.data()["store"];
  const storeDoc = await getDoc(storeRef);
  ...
})

If you have multiple policy documents, you will need to do this for each of them. There is no concept of a server-side join in Firestore (nor in most other NoSQL databases).

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!