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

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

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