问题
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