'Firestore security rules request.writeFields is deprecated

Firestore security rules request.writeFields is deprecated.

Is there any alternative?

For instance, I have three fields in document (name, email, phone number), I don't want to allow users to update phone number.

I can check this by comparing the before and after data. But if I have lot of fields in document then it is very difficult.

So if there is any alternative it will be more helpful.



Solution 1:[1]

You can now use request.resource.data.diff():

// Compare two Map objects and return whether the key "a" has been
// affected; that is, key "a" was added or removed, or its value was updated.
request.resource.data.diff(resource.data).affectedKeys().hasOnly(["a"]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Laurent Payot