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

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

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