Append to an arary field in Firestore

后端 未结 2 589
面向向阳花
面向向阳花 2020-12-07 05:38

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

That\'s how the object looks, and I want to add tasks through the form

相关标签:
2条回答
  • 2020-12-07 06:34

    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")
    });
    
    0 讨论(0)
  • 2020-12-07 06:34

    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)

    0 讨论(0)
提交回复
热议问题