For the life of me, I cannot understand why the following is resulting in a false for allowing writes. Assume my users collection is empty to start
The solution of Tom Bailey (https://stackoverflow.com/a/48177722/5727205) did look promising.
But in my case I needed to prevent a field from being edited, and could have the case, that the field simply does not exist on the existing data. Thereby I added a check if the field exists.
This solution does check two checks:
function isNotUpdatingField(fieldName) {
return
( !(fieldName in request.resource.data) && !(fieldName in resource.data) ) ||
request.resource.data[fieldName] == resource.data[fieldName];
}