Skip to content

Append to an arary field in Firestore

I’m using Firebase and Vuejs to create an database element, which has object array inside.

enter image description here

That’s how the field looks, and I want to add tasks through the form into the ‘moreTasks’ as an array.

I tried using this, but it just creates new entity in the database.

    tasker: this.tasker.taskerName

I also tried checking API but I couldnt understand the refs, because I was using different methods to achieve that goal.

creatTask() {
    task_id: this.task_id,

What would be correct way to approach this problem?


You can append an item to an array using FieldValue.arrayUnion() as described in the documentation. For example:

// Atomically add a new region to the "regions" array field.
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")