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

136
Vistas
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 Respuestas
Responde la pregunta

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