flutter - 扑扑 Firestore 交易这行得通吗?
问题描述
我正在尝试更新值,Transaction
首先我尝试过这样,但应用程序会在tx.get
. 我认为这是插件问题我在 git 中看到了几个问题。
await Firestore.instance.runTransaction((tx) async {
DocumentReference ref = Firestore.instance.collection('votes').document('6z2C2cSwnHNXaRNmzs4P');
DocumentSnapshot snap = await tx.get(ref); // crash here
if (snap.exists) {
await tx.update(snap.reference, {'vote': snap.data['vote'] + 1});
}
});
我刚刚更改tx.get
为ref.get
,它在更新值方面起作用。
那么我想问的是,如果我这样改变,这仍然可以原子地工作吗?
await Firestore.instance.runTransaction((tx) async {
DocumentReference ref = Firestore.instance.collection('votes').document('6z2C2cSwnHNXaRNmzs4P');
DocumentSnapshot snap = await ref.get(); // changed here
if (snap.exists) {
await tx.update(snap.reference, {'vote': snap.data['vote'] + 1});
}
});
解决方案
推荐阅读
- java - 正则表达式匹配 URL 中的文件扩展名
- git - 将分支中的文件签出到不存在此文件的工作分支
- html - 无法在 Chrome 表单自动填充文本上定义字体大小
- angular - Angular Highchart - 设置时区
- c - Not able to insert timestamp data in Cassandra from C program
- docker - Jenkins: Connect to a Docker container from a stage that is run with an agent (another Docker container)
- python - 如何使用 boto3 按 OwnerIds 和 Filters 描述快照
- ios - 如何在 UIButtons 下连续正确移动 UIView
- angularjs - How to use Katalon with AngularJS Ui-select?
- angular - Error : ngModel cannot be used to register form controls with a parent formGroup directive