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

332
Views
Las funciones de reglas de Firestore get () y existe () no devuelven el resultado deseado. ¿Qué estoy haciendo mal?

ingrese la descripción de la imagen aquí

Esta es la estructura básica de la base de datos de Firestore que estoy usando. editar: todos los nombres están en minúsculas

Las reglas que quiero son

  1. los administradores de un albergue pueden leer todas las habitaciones del albergue
  2. los residentes de una habitación solo pueden ver la habitación si la habitación tiene la identificación de los residentes en su subcolección de residentes

1 funciona según lo previsto 2 no

 match /databases/{database}/documents { match /hostels/{hostelId} { allow read, write: if request.auth.uid != null; match /rooms/{roomId} { allow read, write: if exists(/databases/$(database)/documents/ hostels/$(hostelId)/admins/$(request.auth.uid)); allow read: if exists(/databases/$(database)/documents/ hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid)); } } }

mientras leo salas como residente me sale un error

 Null value error. for 'list' @ L49

También probé con get () leyendo un campo booleano de documento residente y sin suerte.

¿Qué estoy haciendo? ¿Existe un límite para la profundidad del argumento de ruta de acceso() y get()? Cualquier ayuda sería muy apreciada

el código que uso para consultar habitaciones por residente es

 let q = collection(this.hostelCollection, this.residentSnap.get('hostel_id'), "rooms") let docs = await getDocs(q);

el documento de residente tiene un campo hostel_id que contiene la identificación del albergue

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente agregar una sola declaración de permiso de allow read y refactorizar las reglas como se muestra a continuación:

 rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /hostels/{hostelId} { allow read, write: if request.auth.uid != null; match /rooms/{roomId} { function isAdmin() { return exists(/databases/$(database)/documents/hostels/$(hostelId)/admins/$(request.auth.uid)); } function isResident() { return exists(/databases/$(database)/documents/hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid)); } allow read: if isAdmin() || isResident(); allow write: if isAdmin(); } } } }
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!