Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!