When writing rules for Firebase Storage, I get a warning that the parameter for firestore.get must always start with /databases/(default)/documents
, like this:
firestore.get(/databases/(default)/documents)
Additionally, according to the warning in the Firebase documentation, multiple databases must be enabled to access documents from the default Cloud Firestore database.
Currently, I have created both a default Firestore database and a custom database. Previously, I was only using the custom database.
When I use firestore.get(/databases/(default)/documents)
, the security rules work fine. However, since all my existing data is stored in the custom database, I need to access it instead.
How should I write the firestore.get
rule to properly access my custom Firestore database instead of the default one?
- Full Security Rule
Here is the complete security rule I am using:
service firebase.storage {
match /b/{bucket}/o {
function findCourse(course) {
return course in firestore.get(/databases/(default)/documents/accounts/$(request.auth.uid)).data.authedCourse;
}
match /video/{course}/{allPaths=**} {
allow read: if request.auth != null && findCourse(course);
}
}
}
The rule allows read access only if the authedCourse
array contains the course value.
- My Attempts
firestore.get(/databases/custom/documents)
This results in an error during simulation, stating that I must use/databases/$(database)/documents/
.firestore.get(/databases/$(custom)/documents)
This results in the following error:
Function not found error: Name: [firestore.get].; Error: Invalid argument provided to call. Function: [firestore.get], Argument: ["||invalid_argument||"]
firestore.get(/databases/{custom}/documents)
This fails to save and produces the following error:
Line 7: Missing 'match' keyword before path.;
Line 7: mismatched input 'creapple' expecting '}';
Line 7: Unexpected '-'.;
Line 7: Unexpected '}'.;
Line 7: Missing 'match' keyword before path.;
Line 7: Forward slash '/' found where identifier or binding expected.;
Line 7: mismatched input '$' expecting {'{', '/', PATH_SEGMENT};
Line 9: Unexpected 'match'.
When writing rules for Firebase Storage, I get a warning that the parameter for firestore.get must always start with /databases/(default)/documents
, like this:
firestore.get(/databases/(default)/documents)
Additionally, according to the warning in the Firebase documentation, multiple databases must be enabled to access documents from the default Cloud Firestore database.
Currently, I have created both a default Firestore database and a custom database. Previously, I was only using the custom database.
When I use firestore.get(/databases/(default)/documents)
, the security rules work fine. However, since all my existing data is stored in the custom database, I need to access it instead.
How should I write the firestore.get
rule to properly access my custom Firestore database instead of the default one?
- Full Security Rule
Here is the complete security rule I am using:
service firebase.storage {
match /b/{bucket}/o {
function findCourse(course) {
return course in firestore.get(/databases/(default)/documents/accounts/$(request.auth.uid)).data.authedCourse;
}
match /video/{course}/{allPaths=**} {
allow read: if request.auth != null && findCourse(course);
}
}
}
The rule allows read access only if the authedCourse
array contains the course value.
- My Attempts
firestore.get(/databases/custom/documents)
This results in an error during simulation, stating that I must use/databases/$(database)/documents/
.firestore.get(/databases/$(custom)/documents)
This results in the following error:
Function not found error: Name: [firestore.get].; Error: Invalid argument provided to call. Function: [firestore.get], Argument: ["||invalid_argument||"]
firestore.get(/databases/{custom}/documents)
This fails to save and produces the following error:
Line 7: Missing 'match' keyword before path.;
Line 7: mismatched input 'creapple' expecting '}';
Line 7: Unexpected '-'.;
Line 7: Unexpected '}'.;
Line 7: Missing 'match' keyword before path.;
Line 7: Forward slash '/' found where identifier or binding expected.;
Line 7: mismatched input '$' expecting {'{', '/', PATH_SEGMENT};
Line 9: Unexpected 'match'.
Share
Improve this question
edited 30 mins ago
Frank van Puffelen
599k85 gold badges889 silver badges859 bronze badges
Recognized by Google Cloud Collective
asked 1 hour ago
EullEull
11 silver badge
New contributor
Eull is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1 Answer
Reset to default 3From the documentation you can only access the default firestore database in storage rules.
Warning: Storage Rules can only access documents from the default Cloud Firestore database when multiple databases are active.