Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda