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

224
Vistas
How can I compare firebase realtime database data (child values)
firebase.database().ref("/user/" + user.uid).set({
  email:user.email, 
  points:"500",
  uid: user.uid
})
  

can i compare the points in my database and points needed and execute the task? Like if the user have 500 points in database but it is required 500 points to carry out an operation on web app is it possible to do so? Any suggestions would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to perform an operation on a path in the database based on its current value, you'll want to use a transaction:

firebase.database().ref("user").child(user.uid).child("points")
  .transaction((currentValue) => {
    if (parseInt(currentValue) > 500) {
      ... do you operation and currentValue and return the result to be written to the database
    }
  })

As said in my answer your previous question, I recommend storing the value of points as a number, so that you don't have to parse it in your code and so that numeric operations become possible on it.

I recommend spending some time reading the Firebase documentation at this point. A few hours spent there now will avoid many such questions going forward.


In addition to (and possibly instead of) this client-side code, you'll also want to validate the points value in your database's security rules. For example, if points must always be a positive number:

{
  "rules": {
    ...
    "user": {
      "$uid": {
        "points": {
          ".validate": "newData.isNumber() &&
                        newData.val() >= 0"
        }
      },
    }
  }
}
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