Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda