Dart Firestore add to array

有些话、适合烂在心里 提交于 2021-02-05 07:10:25

问题


I'm writing a Flutter app and am trying to add an element to an array. I'm trying to follow the example here: https://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array - however, My DocumentReference object does not have an update object:

So, how do I go about adding an element to an array in this document?

For reference, I'm using the cloud_firestore: 0.12.1 dependency.


回答1:


The method you should use is updateData(). You pass to it a map.

Here is an example adding an element (the string 'element') to an array (named loosely 'arrayName') :

userPantry.updateData({'arrayName': FieldValue.arrayUnion(['element'])})


来源:https://stackoverflow.com/questions/56402214/dart-firestore-add-to-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!