Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter firestore overwrites data when I use set data

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?

like image 767
Sam H Avatar asked Apr 10 '26 04:04

Sam H


1 Answers

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()

like image 114
Shady Aziza Avatar answered Apr 11 '26 16:04

Shady Aziza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!