javascript - 更新 Firebase 实时数据库中的现有值
问题描述
我想添加到 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
});
}
});
解决方案
解决了,如果这对某人有帮助...
console.log("val",snapshot.val().points);
推荐阅读
- node.js - 需要 app.set('views' , path.join(__dirname , 'views')) 的逻辑含义
- java - JavaFX TableView 不更新值
- python - 有没有办法在熊猫数据框中的列之间动态地找到部分匹配数?
- javascript - 尝试对数据抓取进行身份验证时出现 Cookie 错误
- java - 面对异常HibernateException:实例的标识符
从 至 春天 - uwp - Xbox Series X 开发模式媒体捕获/远程查看
- python - 如何在 Python 中使用 selenium 单击按钮类
- flutter - 从一个由数字和逗号组成的字符串中返回整数列表
- node.js - 无服务器部署期间出现错误“无法读取未定义的属性‘名称’”
- checkout - 使用自托管代理解压缩时 GitHub Action 结帐失败