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

326
Views
Cómo configurar una variable en las reglas de la base de datos en tiempo real de firebase

Así que mi base de datos se ve así:

ingrese la descripción de la imagen aquí

Y mis reglas se ven así:

 { "rules": { ".read": true, ".write": true, "_default_user":{ <---- this is what I need to change "cart":{ ".indexOn": "product/id" } } } }

Este es mi código para eliminar un producto del carrito:

 removeFromCart(itemRemoved){ let account = JSON.parse(localStorage.getItem('user')) === null ? '' : JSON.parse(localStorage.getItem('user')).email account == '' ? account = ['_default', ''] : account = /([^@]+)/.exec(account) const cartRef = firebase.database().ref('/' + account[0] + '_user' + '/cart'); // Do I need to change this ^ as well? const itemQuery = cartRef.orderByChild("product/id").equalTo(itemRemoved.id); let itemRef:any = '' itemQuery.get().then((snapshot) => { snapshot.forEach((productSnapshot) => { itemRef = firebase.database().ref('/' + account[0] + '_user' + '/cart' + '/' + productSnapshot.key); }) itemRef.remove() }) }

Por ahora, para eliminar un artículo del carrito, necesito agregar manualmente cuentas a mis reglas, lo cual, por supuesto, no es factible. Básicamente, necesito tener indexOn en todas las cuentas posibles sin tener que hacer todo eso manualmente.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Resulta que solo necesito hacer esto:

 { "rules": { ".read": true, ".write": true, "$user":{ // <--- "cart":{ ".indexOn": "product/id" } } } }

Simplemente escriba la variable y .indexOn se aplicará a cada nodo en la raíz (en mi caso)

https://firebase.google.com/docs/database/security/core-syntax

over 4 years ago · Santiago Trujillo 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!