【发布时间】:2019-10-24 23:59:13
【问题描述】:
功能:
我有一个获取项目列表的函数 batchItemUpdate。每个项目都有一个称为批次的数组。我正在更新项目列表中每个项目的批次。因为可能有很多项目我正在使用批量写入所以所以。检查下面的代码:
batchItemUpdate(items: Item[]) {
var transactionBatch = this.afs.firestore.batch();
items.forEach((item)=>{
const sfDocRef = this.afs.firestore.collection('items').doc(item.id);
transactionBatch.update(sfDocRef,
{
batches:item.batches
});
});
return transactionBatch.commit();
}
问题: 事务已成功提交,但仅写入批次数组中的最新批次。 item 中的批次数组中的所有其他批次都将被删除。
if previously item.batches was [1,2,3,4]
to be updated with [1,2,3,5]
now item.batches is [5]
【问题讨论】:
标签: angular firebase google-cloud-firestore angular7