PacMan Programador
PacMan Programador

Reputation: 200

Firestore. Add new array instead of replacing it

I am trying to store orders(quantity, price, date, etc), I want to store each one in different arrays inside an array called "orders", but when I send the data, instead of creating a new array, it overwrites the one that was already there

this is my code

TS

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

The data is obtained directly from a form

Upvotes: 0

Views: 313

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317477

If you want to add a new item to an array, you should use FieldValue.arrayUnion() to add to the existing array.

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

Upvotes: 1

Related Questions