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


Solution 1:[1]

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');
        }
    })   
  })
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marc Anthony B