Flutter firestore overwrites data when I use set data

主宰稳场 提交于 2020-08-10 20:15:51

问题


I have been trying to add data to sections in my firestorm database, I have a collection -> document -> data fields. Whenever I use setData({'key': 'value'}) is always overwrites the data already in the document. Is there anyway around this?


回答1:


That is because what setData(object) is used for

To create or overwrite a single document

While update(object)

To update some fields of a document without overwriting the entire document

So what you need is to use update()




回答2:


Using merge: true in your setData() statement prevents overwrite. This seems similar to the update() method but you can use it even when document does not exist (ie is being created).



来源:https://stackoverflow.com/questions/49801496/flutter-firestore-overwrites-data-when-i-use-set-data

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