Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!