当我使用设置数据时,Flutter Firestore会覆盖数据 [英] Flutter firestore overwrites data when I use set data

查看:63
本文介绍了当我使用设置数据时,Flutter Firestore会覆盖数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将数据添加到firestorm数据库的各个部分中,我有一个collection-> document-> data字段。每当我使用setData({'key':'value'})时,总是会覆盖文档中已经存在的数据。

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?

推荐答案

那是因为 setData(object)用于


创建或覆盖单个文档

To create or overwrite a single document

同时 update(object)


要更新一些文档的字段而不覆盖整个文档

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

所以您需要使用 update()

这篇关于当我使用设置数据时,Flutter Firestore会覆盖数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆