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

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

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 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