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

102
Vistas
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 Respuestas
Responde la pregunta

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