Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore doc Update with Merge true

Today while working on Cloud Firestore using Admin SDK, I accidentally forget to replace .update with .set with merge true option and to my surprise the query worked and document got created. I removed merge:true and then I got document not exists error. I tested it again with merge:true and document created again. I could not find anything about this in documentation. Can anybody explain this behavior.

let query = userRolesRef
           .doc(user).update(
                    {
                      isDeliveryPerson:true
                    },
                     { merge: true }
                );
like image 962
Deependra Solanky Avatar asked Nov 02 '25 14:11

Deependra Solanky


1 Answers

There is no difference between using .update and .set with merge true option for documents that already exist in your collection. The difference between these two operations comes only for documents that do not exist. For instance, .set with merge true option will create the document if the document does not exist, while when using and .update, the operation will fail.

like image 191
Alex Mamo Avatar answered Nov 04 '25 03:11

Alex Mamo



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!