Javascript 更新Firebase实时数据库中的现有值
我想添加到Firebase中的现有值 我有一个updatePoints函数来查找用户,如果他们已经存在,我想查找现有的点并添加newPoints值。我怎样才能做到这一点与下面的请Javascript 更新Firebase实时数据库中的现有值,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我想添加到Firebase中的现有值 我有一个updatePoints函数来查找用户,如果他们已经存在,我想查找现有的点并添加newPoints值。我怎样才能做到这一点与下面的请 updatePoints(userID, newPoints){ firebase.database().ref('/userProfile').child(userID).once('value', function(snapshot) { var exists = (snapshot.val() !== nul
updatePoints(userID, newPoints){
firebase.database().ref('/userProfile').child(userID).once('value', function(snapshot) {
var exists = (snapshot.val() !== null);
if (exists) {
console.log('user ' + userID + ' exists!');
firebase.database().ref('markets/'+userID).update({
points: newPoints // I want to look up eixsitg points and add on newPoints,
});
} else {
console.log('user ' + userID + ' does not exist!');
firebase.database().ref('/markets').child(userID).set({
points: 1
});
}
});
解决了,如果这对某人有帮助
console.log("val",snapshot.val().points);