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 }
);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With