Skip to content Skip to sidebar Skip to footer

Append To An Arary Field In Firestore

I'm using Firebase and Vuejs to create an database element, which has object array inside. That's how the field looks, and I want to add tasks through the form into the 'moreTasks

Solution 1:

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.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

Solution 2:

The accepted answer used to be correct but is now wrong. Now there is an atomic append operation using the arrayUnion method: https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array

This is true as long as you are using firestore and not real time db (which I assume is the case from the tags)

Post a Comment for "Append To An Arary Field In Firestore"