消防站。添加新数组而不是替换它

时间:2020-09-19 15:04:29

标签: arrays angular google-cloud-firestore

我正在尝试存储订单(数量,价格,日期等),我想将每个存储在称为“订单”的数组内的不同数组中,但是当我发送数据时,而不是创建一个新数组,它会覆盖已经存在的那个

这是我的代码

TS

this.FireServices.collection("clientData").doc(uid).update({
orders: [this.dataForm.value]
})

数据直接从表单获取

1 个答案:

答案 0 :(得分:1)

如果要将新项目添加到数组,则应use FieldValue.arrayUnion()添加到现有数组。

this.FireServices.collection("clientData").doc(uid).update({
    orders: firestore.FieldValue.arrayUnion(this.dataForm.value)
})