我正在尝试用
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});
}
});
我刚换了
德克萨斯州
到
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});
}
});