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

154
Views
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 answers
Answer question

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