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

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

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 Relatório

0

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