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

170
Vistas
calling specific data from inside Firebase array

so my firebase document looks like this:

enter image description here

So it is a list with name, imgUrl etc inside of the list. My problem right now with firebase cloud firestore, is that I just want to extract all the "name:" stuff so that I can count how many times a particular name appears.

I am retrieving the data from the document like so:

 const matchLikes = async () => {
       await fire.firestore()
        .collection("eventLikes")
        .doc(eventID).onSnapshot((querySnapshot) => {
            
                //console.log("print indi event heree  " + querySnapshot.data().eventID)
              
                setLikes(querySnapshot.data().ActivityLikes)
              
            
        })

and I have the array in a hook to use, but i just cant figure out how to access just the "name:" stuff inside the array I have tried even doing querySnapshot.data().ActivityLikes.name but it fails. Does anyone know where I am going wrong?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Firestore doesn't support projecting specific fields and aggregating the data. You'll have to fetch the document and then manually find count of each name. Also there you don't need an await before onSnapshot. Try refactoring the code as shown below:

const matchLikes = () => {
  fire.firestore()
    .collection("eventLikes")
    .doc(eventID).onSnapshot((docSnapshot) => {
      const nameCounts = docSnapshot.data().ActivityLikes.reduce((acc, cur) => {
        acc[cur.name] = (acc[cur.name] || 0) + 1;
        return acc;
      }, {});
    
      //  setLikes(querySnapshot.data().ActivityLikes)
    })
}
about 4 years ago · Santiago Gelvez 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