Firebase事务[错误:设置]

时间:2015-05-10 04:14:27

标签: node.js firebase

我正在使用firebase for node,当我尝试使用事务创建商店数据时,我得到:

[Error: Set]

我很难弄清楚这个错误代码的建议。我重写了我的代码,暂时禁用了安全规则,但我得到了同样的错误。

这是我正在使用的代码:

        myRef.child(user).transaction(function(currentData) {
            if (currentData === null) {
                //data doesn't exist
                return {
                    total: userTotal,
                    left: userLeft,
                    isText: userIsText
                };
            } else {
                currentData.total += userTotal;
                currentData.left += userLeft;

                return {
                    total: currentData.total,
                    left: currentData.left,
                    isText: currentData.isText
                };
            }
        }, function(error, committed, snapshot) {
            if(error) {
                console.log('@line 281: FB Tx failed', error);
            } else if (!committed) {
                console.log('FB Tx aborted');
            }
        });

我得到的实际控制台错误消息当然是:

@line 281: FB Tx failed [Error: Set]

有关错误代码应该表示什么样的错误/代码中出错的任何见解?我在剧本的其他地方有几乎完全相同的代码,实际上是有效的,所以我很困惑......

提前致谢!

1 个答案:

答案 0 :(得分:7)

您看到的错误表明该交易因您在应用/代码中的其他地方写入而被中止。

Firebase事务通过将本地转换函数应用于数据的当前状态并将新状态写入服务器来工作。但是,如果您在代码中的其他位置呼叫ref.set(...)ref.update(...)ref.remove(),则无论如何都会破坏该路径的更改,这就是交易中止的原因。

如果您在跟踪该路径中的更改时遇到问题,请尝试在应用开始时使用Firebase.enableLogging(true)来查看Firebase客户端正在做什么。

相关问题