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

271
Visualizações
Converting firebase 8 code to firebase 9 code (web, javascript) to fetch collection within collection

Hello I would like to convert the following firebase 8 code to firebase 9 and have no clue how to do it - any help would be welcome!

This piece of code should go inside the userDoc and then fetch the collection that is insdie that document and return all of the posts that belong to that user

if (userDoc) {
    user = userDoc.data()
    const postsQuery = userDoc.ref
        .collection('posts')
        .where('published', '==', true)
        .orderBy('createdAt', 'desc')
        .limit(5)
    posts = (await postsQuery.get()).docs.map(postToJSON)
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firestore's documentation has examples for both V8 and V9 so you can easily compare them and modify your code. Just switch to modular tab for the new syntax. The code in question would be like:

import { collection, query, where, getDocs, orderBy, limit } from "firebase/firestore";

const q = query(collection(db, "posts"), where("published", "==", true), orderBy("createdAt", "desc"), limit(5));

const querySnapshot = await getDocs(q);

posts = querySnapshot.docs.map(postToJSON)
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