我有一个循环,使用事务将数据添加到Firestore数据库。
jQuery.each(objIN, function (key, value) {
var product = products.doc(key);
db.runTransaction(function (transaction) {
return transaction.get(product).then(function (doc) {
...
...
transaction.update(product, {
productQTY: newProductQTY,
[warehouseIN]: newSelectedWarehouseQTY
});
});
}).then(function (newProductQTY) {
console.log("New product qty ", newProductQTY);
}).catch(function (err) {
// This will be an "population is too big" error.
console.error(err);
});
})这样做是可以的,还是把循环放在事务中更好。批量更新firestore的最佳选择是什么?
发布于 2019-10-10 21:17:22
Firestore支持的两个批量update语句(transaction和batch)用于帮助确保多个文档之间的数据一致性。使用批量更新不会带来性能上的提升。事实上,如果更新中没有跨文档一致性的要求,那么运行单独的小更新通常会更快,因为有机会(在客户端代码中)并行化这些更新。
所以:是的,你所做的一切都很好。:)
https://stackoverflow.com/questions/58322376
复制相似问题