I am trying to figure out how to get an array from the path on an update or create in order to create validators based on the path data:
function test() {
// option 1
return string(request.path).split('/')[0] == 'databases';
// option 2
// return string(request.resource.__name__).split('/')[0] == 'databases';
}
match /posts/{document} {
allow update: if test();
...
}
I have tried both of the previous examples with request.resource.__name__ and request.path... How do I parse the data out of the requested path?
Thanks,
J
Lets assume this is my request.path /databases/%28default%29/documents/posts/123456.
function test(docId) {
// request.path supports map access.
return request.path[4] == '123456'; // this will return true;
return request.path[3] == 'posts'; // this will return true;
return docId == '123456'; // this will return true;
}
match /posts/{documentId} {
allow update: if test(documentId);
}
So if your path has 5 segments, request.path[4] && request.path[3] will return the last 2 segments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With