我想使用Firebase事务功能更新对象。我阅读了所有文档和所有可用资源。如果特定节点上有数据,则事务功能下方的功能是从该节点删除数据。有人可以帮我吗,下面的代码有什么问题?
注意:-使用事务而不是更新功能,因为可以同时更新值。
await refRun.once('value', snap => {
console.log(snap.val()); // Here I am able to get data
})
refRun.transaction(async (current) => {
if (current === null) {
console.log("coming", current);
// updating values by fetcing from node
return await refRun.once('value', function (snapshot) {
console.log("coming", snapshot.val()); // coming null here
if (snapshot.val() === null) {
console.log("coming----1", snapshot.val());
return {
total_raised: workout.run_amount || 0,
total_distance: workout.distance || 0.0
}
}
else {
console.log("coming----2", snapshot.val());
return {
user_total_raised: snapshot.val().user_total_raised + workout.run_amount || 0,
user_total_distance: snapshot.val().user_total_distance + workout.distance || 0.0
}
}
})
}
console.log("coming-123", current); // null
});