I have a document with a map in it like so:
keys: {
value1: true
value2: true
value3: true
}
I want to allow a user to read that document if any values in a separate document's array match any one of the map keys. The external document is setup like this:
values: [
0: value1,
1: value5,
2: value6,
]
Since the external document array contains "value1" and it matches the key "value1" in the "keys" map, it should allow the read.
I know I can retrieve the external document array using get(/databases/$(database)/documents/myCollection/myDoc).data.values;
But I do not know how to make the comparison properly.
To check if a map has any key that exists in an array:
theMap.keys().hasAny(theArray)
Note that this doesn't care at all what the value is for each key. It's just checking the existence of that key in the map.
So the whole rule would look something like this:
allow read: if resource.data.keys.keys().hasAny(get(...).data.values);
I suggest reviewing the API documentation for Map and List to see other operations.