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

243
Vistas
Firebase v9.01 - Unhandled Rejection (TypeError): productDoc.ref.collection is not a function

I encountered an issue when fetching data from firestore. I can't really figure out why isn't there a collection function under productDoc.ref, and would highly appreciate if anyone could help with this.

I'm using the latest version of Firebase, but still have no access to the prices subcollection if i were to follow docs from firebase v9.

useEffect(() => {
  const q = query(collection(db, "products"), where("active", "==", true));
  // console.log(db.collection("products").getDocuments());
  const unsub = onSnapshot(q, (querySnapshot) => {
    const products = {};
    querySnapshot.forEach(async (productDoc) => {
      products[productDoc.id] = await productDoc.data();
      console.log(await productDoc, "ref");

      const priceSnap = await productDoc.ref.collection("prices").get();
      priceSnap.doc.forEach((price) => {
        products[productDoc.id].price = {
          priceId: price.id,
          priceData: price.data(),
        };
      });
    });
    setProducts(products);
  });
}, []);

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't chain the collection call from a DocumentReference object in the modular API.

You instead need to pass the DocumentReference to a call to the top-level collection function:

const priceSnap = await getDocs(collection(productDoc.ref, "prices"));
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