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

123
Views
Retrieving sub collection from firebase

I'm trying to retrieve a sub collection from firestore database using Angular. I have collection 'Company' containing fields 'Name' and 'Id' and subcollection 'CustomerList' containg fields 'Name' and 'Id'

To retreive Company collection I have code:

private companyCollection: AngularFirestoreCollection<Company>;
getCompany() {
  return this.company= 
    this.companyCollection.snapshotChanges().pipe(
      map(changes => {
        return changes.map(a => {
          const data = a.payload.doc.data() as Company;
          return data;     
        });

My question is how to retreive 'CustomerList' sub collection and add it to 'Company' object.

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

0

Here are 2 things:

1 If your collection is object like:

Before you check you need to define relations between your customers and companies.

interface customer {
 id: any;
 name: string;
}
interface Company { 
  id: any;
  name: string;
  customerList: customer[];
}

Here is very simple example:

const customers = [
 {
   id: 0,
   name: 'lilu',
 },
 {
   id: 1,
   name: 'lilu1',
 },
 {
   id: 2,
   name: 'lilu2',
 },
 {
   id: 3,
   name: 'lilu3',
 }
 ];

 const companies = [
 {
   id: 0,
   name: 'lilu Company',
 },
 {
    id: 1,
    name: 'lilu1 Company',
   },
 {
   id: 2,
   name: 'lilu2 Company',
 },
 {
id: 3,
name: 'lilu3 Company',
  },
  ];

  let customersWithCompanies = [];

  for (let item of companies) {
       let obj = {
         id: item.id,
          name: item.name,
           customerList: customers
          };
         customersWithCompanies.push(obj);
   }
    console.log(customersWithCompanies);

If this is collection prototype you need js/ts functions to get, set specific data and then push to firebase;

2 You have to different collections in firebase and they are connected to each other (Mayby on Idea level)

In this case you need to fetch data from different collections here is part of code from documentation.

From firebase documentation you need to define it like this:

import { doc } from "firebase/firestore"; 

const alovelaceDocumentRef = doc(db, 'users/alovelace');

Please view followin url: https://firebase.google.com/docs/firestore/data-model#web-version-9_2

If I didn't catch subject well please wite a comend and I'll make answer more clear with examples.

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!