【发布时间】:2021-08-21 16:51:47
【问题描述】:
我有一个批次,其中包含对数据库中不同文档的多个引用,我想在一个 batch.commit 中更新它们,这样我就可以跟踪计数。因此我使用增量来更新字段值。通常它工作正常,但在某些情况下它看起来像 batch.commit 被执行了多次。我已经看到它多次更新字段,并且仅在最后我收到一次承诺,并且控制台上记录了“来自 ref 的测试 ID”。下面附上代码。它可能连接到一个非常慢的互联网连接。 firebase 是否会在内部重试批量写入?还是我错过了其他东西? 我会很高兴任何提示! 维拉
const increment = firebase.firestore.FieldValue.increment(1);
const decrement = firebase.firestore.FieldValue.increment(-1);
const batch = this.db.batch();
batch.set(reqRef, testData);
batch.set(statsRef, { testCount: increment }, { merge: true });
batch.set(statsRef2, { testCount: increment }, { merge: true });
batch.set(statsRef3, { testCredits: decrement }, { merge: true });
batch.commit().then(val => {
console.log('Test ID from ref ', reqRef.id);
res(reqRef.id);
}).catch(err => {
console.log('test save batch error ', err);
rej(err);
});
【问题讨论】:
标签: angular firebase google-cloud-firestore