Javascript Firestore中的交易;“每个循环”;事务中的or循环
我有一个使用事务将数据添加到Firestore数据库的循环Javascript Firestore中的交易;“每个循环”;事务中的or循环,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,我有一个使用事务将数据添加到Firestore数据库的循环 jQuery.each(objIN, function (key, value) { var product = products.doc(key); db.runTransaction(function (transaction) { return transaction.get(product).then(function (doc) { ... ...
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的最佳选项是什么 Firestore支持的两个批量更新语句(事务和批处理)有助于确保多个文档之间的数据一致性。使用批量更新不会提高性能。事实上,如果在更新中不需要跨文档一致性,那么运行单独的小更新通常会更快,因为有机会并行化这些更新(在客户端代码中) 所以:是的,你现在做的很好。:)