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

126
Vistas
How to add previous data with new one in firebase realtime database javascript
function add(){
  firebase.database().ref("user/l6xetRv3ddhjlerJm10d3aYkF3w1" ).update({            
    points: "2000"
  })
}

I am using this code above to update a specified user points for test but I want to update points of currently logged in user. I tried doing it on function onAuthStateChanged block, but it was unsuccessful. Any suggestions how should I do it?

And is it possible to update previous points adding with current update points? for example:- the previous points of user is 2000, the update function updates 2000 points but i want it to update previous points + current points which is goona be update (2000+2000).

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

0

To write the points of the currently sign in user:

const uid = firebase.auth().currentUser.uid;
firebase.database().ref("user").child(uid).update({            
  points: "2000"
})

To increment/decrement the points of the user, you can use the atomic increment operator:

const uid = firebase.auth().currentUser.uid;
firebase.database().ref("user").child(uid).update({            
  points: firebase.database.ServerValue.increment(2000);
})

Note that this will only work if you've stored the points as a number though, so:

firebase.database().ref("user").child(uid).update({            
  points: 2000 // 👈 without quotes
})

And then

firebase.database().ref("user").child(uid).update({            
  points: firebase.database.ServerValue.increment(2000);
})
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