2
votes

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 }
                );
1
You are right, using the Admin SDK it creates a new doc (I've verified it in a Cloud Function). I've thoroughly looked at the Node.js documentation and I don't see any reason why it shoudl do that, even if, with the Node.js Admin SDK the update() method can take several parameters. I would suggest you contact Firebase support and/or you post in this Google Group: groups.google.com/forum/#!forum/firebase-talk - Renaud Tarnec

1 Answers

1
votes

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.