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

285
Vistas
Checking if a userID is the document name in Firebase

so I have these document ID's: https://i.stack.imgur.com/APlE3.png These are basically user groups.

I have a collection like:

fire.firestore()
            .collection("groupsCategory")
            .doc(groupID)
            .collection('events')
            .doc(eventID)
            .collection('memberPicks')
            .doc(currentUserID)

so with my object array, I am trying to do a for loop that checks if the currentUserID is in each of the groupID's from the collection above. My if logic is off and I'm not sure how to go about doing it. Is this approach okay or is there a better way to loop through the object array of groupID's and check if the ID is the documentName to determine if a user has picked their options

    for (let i = 0; i < groupsArray.length; i++) {

        await fire.firestore()
        .collection("groupsCategory")
        .doc(groupsArray[i])
        .collection('events')
        .doc(eventID)
        .collection('memberPicks')
        .onSnapshot((querySnapshot) => {
            querySnapshot.forEach((doc) => {
                if 
        
      }   
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As far as I understand, you're doing it right. You just have to continue to check if the documents in the memberPicks collection have the same ID with the groupsArray. See code below:

// Used `foreach` instead of `for` loop for ease of reading.
groupsArray.forEach(async (groupId) => {
  await fire.firestore()
  .collection("groupsCategory")
  .doc(groupId) // If the groupId does not exist, the query just ignores them.
  .collection('events')
  .doc(eventID)
  .collection('memberPicks')
  .onSnapshot((querySnapshot) => {
    querySnapshot.forEach((doc) => {
        if (groupsArray.includes(doc.id)) {
          // `memberPicks` document is in the `groupsArray`
          console.log(doc.id, 'true');
        } else {
          // `memberPicks` document is not in the `groupsArray`
          console.log(doc.id, 'false');
        }
    })   
  })
})
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