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

139
Views
Firestore load document if user is a member

I have two collections: groups and users

I would like to perform a query that will return all groups where a user has a particular role assigned.

A group looks like this

{
  "name": "myGroupName",
  "members" : {
    "firstUsersID" :
      {
        "roles" : ["user", "admin"]
      },
      "secondUsersID" :
      {
        "roles" : ["user" ]
      },
  }
}

Is there a way to perform queries in react native/web SDK which will return

  1. All groups where a given user e.g firstUserID is listed in the members map/object
  2. All groups where a given user e.g firstUserId has a particular role e.g "admin"

Alternatively would I have to create an array/map on the user object listing their roles? Are there advantages/disadvantages to each route?

Currently I have the following which returns all groups

const colRef = collection(db, "groups");
const q = query(colRef)
const colSnap = await getDocs(q)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured it out I think

The following works

const colRef = collection(db, "groups");
const q = query(colRef, where("users." + user.uid + ".roles", "array-contains", "admin"))

In this case I am dynamically getting the uid of the current authenticated user but you could also hardcode it using

const q = query(colRef, where("users.firstUserID.roles", "array-contains", "admin"))
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!