Reputation: 382
I'm trying to DRY up my rules so I'm writing a function like this
function isInCollection(field, collection) {
return exists(/databases/$(database)/documents/$(collection)/request.resource.data[field])
}
I've tried at least six permutations of this argument to exists()
including using the path()
function to construct a path out of a string and I can't get it to properly resolve the path. I'm suspicious that the issue is related to the []
notation around field.
Upvotes: 1
Views: 430
Reputation: 317412
It's the same syntax as you're already using to interpolate database
and collection
. Use $()
to contain the expression you want to add to the path.
exists(/databases/$(database)/documents/$(collection)/$(request.resource.data[field]))
Upvotes: 2