Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用firebasedatabase事务?_Javascript_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 如何使用firebasedatabase事务?

Javascript 如何使用firebasedatabase事务?,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我想在我的react本机应用程序中使用firebase数据库事务。我想在数据库中添加用户时更新用户数 这是我正在使用的代码 let dbCountPath = "/DatabaseUsersCount/" + "count" dbCountPath.transaction(function (current_value) { return (current_value || 0) + 1; }); 我得到错误的交易是不存在的?我们如何解决此问题?您试图调用字符串上

我想在我的react本机应用程序中使用firebase数据库事务。我想在数据库中添加用户时更新用户数

这是我正在使用的代码

let dbCountPath = "/DatabaseUsersCount/" + "count"

    dbCountPath.transaction(function (current_value) {
      return (current_value || 0) + 1;
    });
我得到错误的交易是不存在的?我们如何解决此问题?

您试图调用字符串上的事务。但是事务方法仅在引用上定义,因此首先必须获取路径的引用。比如:

let dbCountPath = "/DatabaseUsersCount/" + "count"

firebase.database().ref(dbCountPath).transaction(function (current_value) {
  return (current_value || 0) + 1;
});