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

100
Views
Problem with request from Subcollection in Firestore

Hey I try to fix a Problem I need to get a subcollection based on a query before.


 const kurzRef = collectionGroup(db, 'kurzwaffensub' );
 const FirstOperation = query(kurzRef,where("kurzModell", "==", `${kurzModell}` ));
    


const getWaffenDaten = async () => {
    const modell = await getDocs(FirstOperation);
    const data = [];

for (const doc of modell.docs) {



  const parentDoc = await getDoc(doc.ref.parent.parent);
  const { Name, avatarPath } = parentDoc.data();

  // Thats the code snippet which I have my problem with 
  const  waffenbilderRef = collection(db, 'users', doc.data().uid, 'waffenbildersub')
      let subCollectionDocs = await getDocs(waffenbilderRef)
  // 


     data.push({
       ...doc.data(),
          Name,
          subCollectionDocs,
          avatarPath
     });

The documents which I get with the first operation have a String Fieldvalue of the document ID

After that I need to get the subcollection based on the Fieldvalue document ID Which is one of 3 subcollections which you can see in the picture.

enter image description here

Unfortunately I get something back which I dont fully understand

enter image description here

As you can see I get the subCollectionDocs, but it doesn't display the Data.

You can see next to the RED marked Arrow that there are 2 Documents in the result of the subcollectionDocs. This is right but I don't know how to retrieve the data properly.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're adding the full DocumentSnapshot from the subcollection query to your state, which is what then shows when you console.log it.

My guess is that you're expecting to just see the document's data and ID, which you can do with:

const subCollectionDocs = await getDocs(waffenbilderRef)
const subCollectionData = subCollectionDocs.docs.map((doc) => {
  return { id: doc.id, ...doc.data() };
}
console.log(subCollectionData);

 data.push({
   ...doc.data(),
      Name,
      subCollectionData,
      avatarPath
 });
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!