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

155
Vistas
How to query firestore collection using reference field

I have 3 firestore collections

enter image description here


enter image description here


enter image description here

I use Angular 13 with @angular/fire ("firebase": "^9.4.0")

Now to get all projects of an user I have this code

import { Firestore, collectionData, collection, docData, doc, getDocs, query, where } from '@angular/fire/firestore';
...
constructor(private firestore: Firestore){}

async getProjects() {

        // get user
        const user = await firstValueFrom(docData(doc(this.firestore, '/users/ebq3CamTAWN8TFL5JCA6jdwIK2K3')))

        // get organizationRef
        const organizationRef = doc(this.firestore, user.organization.path)

        // get projects
        const projects = query(
            collection(this.firestore, 'projects'),
            where("organizationRef", "==", organizationRef)
        )

        const querySnapshot = await getDocs(projects)

        querySnapshot.forEach((doc) => {
            console.log(doc.id, " => ", doc.data());
        })
    }

Is there a way to query this in one shot?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From your question it seems you want to do something like a join query or something like subquery which is possible with relational databases. With Firestore it is not possible to do something like that. So the task you are doing can not be done using a single query. A Firestore query can only get documents from a single collection at a time. If you need to get data from multiple collections you have to write multiple queries as you did in your code to get the desired result.

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