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
Your rules will be a lot more readable and maintainable if you create a custom function to check for updates. For example:
service cloud.firestore {
match /databases/{database}/documents {
function isUpdatingField(fieldName) {
return (!(fieldName in resource.data) && fieldName in request.resource.data) || resource.data[fieldName] != request.resource.data[fieldName];
}
match /users/{userId} {
// Read rules here ...
allow write: if !isUpdatingField("role") && !isUpdatingField("adminOnlyAttribute");
}
}
}