Firestore交易冻结

时间:2020-08-04 11:15:16

标签: node.js firebase google-cloud-firestore

我正在尝试使用事务读取文档,并且如果满足特定条件,则不使用事务更新同一文档。因此,我期望交易失败(因为这是交易的重点,如果我是正确的话,是原子的,如果在交易期间读取的文档已更改,也就是失败)和写入任务(没有交易)成功完成。

但是,代码会永久冻结在这里。

如何实现我的上述期望? (或者唯一的方法是手动抛出错误??)

        await this.firestoreProvider.fs.runTransaction(async transaction => {
            const update = {
                foo: 'foo',
            }
            const test = await transaction.get(this.firestoreProvider.testsRef.doc('test'));
            console.log(test.data());
            await this.firestoreProvider.testsRef.doc('test').set(update);
            // do not continue if the above line caused this transaction to fail
            // ... some more writes using the transaction ...
        })

文档说:

事务可能由于以下原因而失败:

...

该交易读取了在 交易。在这种情况下,事务将自动再次运行。 重试该交易次数。

我试图将maxAttempt设置为5,但它仍然永久冻结。

0 个答案:

没有答案
相关问题