In Cloud Firestore Rules - I have a document called task
and I want to see if some data (assignee
field) is null / don't exists.
I've tried:
resource.data.assignee == null
- Does not work (Error)!resource.data.hasAll(['assignee'])
- Does not work (Error)From the documentation - it states that this indeed creates an error:
// Error, key doesn't exist
allow read: if resource.data.nonExistentKey == 'value';
Reading the list comparisons of the Firestore Security rules documentation here, we can see that hasAll
returns true if all values are present in the list.
// Allow read if one list has all items in the other list
allow read: if ['username', 'age'].hasAll(['username', 'age']);
The request.resource.data
is a map containing the fields and values. In order to use hasAll
, we must first get the keys as a list of values as shown here.
!resource.data.keys().hasAll(['assignee'])