• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

488
Views
How to fetch document and sub-document on Firebase

I'm trying to fetch a document from my firebase using AngularFire2. My goal is to fetch the document and then based on that ID send another request to fetch a sub-collection on that very same document.

I tried using switchMap but it didn't do the trick, how can I do that? This is my implementation for the first call, where I get document.

getUsers(start?: number): Observable<BasicUser[] | any> {
    const q = this.af.collection(this.COLLECTION_PATH, ref =>
        ref.limit(25)
           .orderBy('creationDate')
           .startAt(start || 0))
        .snapshotChanges()
        .pipe(
            map(snaps => {
                return snaps.map(snap => {
                    const data: any = snap.payload.doc.data();
                    return {
                        id: snap.payload.doc.id,
                        firstName: data.firstName,
                        lastName: data.lastName,
                        creationDate: data.creationDate
                    } as unknown as BasicUser;
                })
            })
        );
    return q;
}

Inside that document has a sub-collection called private, I need to fetch that data.

about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error