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

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

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