Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda