我想添加到Firebase中的现有值 我有一个updatePoints函数来查找用户,如果它们已经存在,我想查找现有的点并添加newPoints值。我该如何使用以下内容?
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
});
}
});
答案 0 :(得分:0)
解决了,如果这可以帮助某人...
console.log("val",snapshot.val().points);