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

358
Views
Firebase v9 ,Cannot get document from a nested collection

I feel like it was easier to get subcollection in v8 ,It's been like 2 days trying to do it the new way but I gave up.

Im building a simple react social media app for learning purposes. where each user logs in and be able to post some text (and images but not atm), I have a main collection for Users and it has the users ID .each of these users have a collection called Posts and it contains all the user posts.

here i want to access the Post collection for each user and then access the posts

I can do so by entering the UID of each user like so

but I can only access the current user id

so what can i do to access the Users collection then get ALL the users and be able to access the Posts subcollection?

ps : sorry if any part of this question is unclear ,english isn't my first language and it's my first time posting here. appreciate any help!.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If you want to fetch posts from all the users, you are looking for collectionGroup queries using which you can fetch documents in all the sub-collections named as 'posts'. You can run a collectionGroup query using Modular SDK (V9) as shown below:

import { getFirestore, getDocs, collectionGroup } from "firebase/firestore"
const db = getFirestore()

const allPosts = await getDocs(collectionGroup(db, "posts"))
about 4 years ago · Juan Pablo Isaza Report

0

const docRef = doc(db, "Users", currentUser.uid);
const docSnap = await getDocs(collection(docRef, "Posts");)
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!