1
votes

Consider that you have a collection called user with documents such as:

data class User(
        val name: String = ""
)

And also have a google cloud function which is triggered onUpdate.

What happens if I do this for an non-existing document:

fs.collection("users").document("new-user").set(hashMapOf("name" to "Jane"), SetOptions.merge())

and later do this again (now document exists):

fs.collection("users").document("new-user").set(hashMapOf("name" to "Jane"), SetOptions.merge())

According to the documentation:

onUpdate: Triggered when a document already exists and has any value changed.

I want to know if my function is triggered in my example (no field has been updated). No property of the collection has been updated, but I am guessing that some metadata (e.g. update timestamp) must have been changed.

1

1 Answers

1
votes

If the set call does not change any value, none of the functions onWrite and onUpdate will be updated independently of the merge settings.

However, the fields that will be updated on the set operation depend on the SetOptions from documentation.

public static SetOptions merge ()

Changes the behavior of set() calls to only replace the values specified in its data argument. Fields omitted from the set() call will remain untouched.