I have this code below that is working, but it causes extra reads in my code, I am getting the value that is stored inside the data collection (premiumUntill
) in order to allow/block Crud in to sub collection. Are there any other methods that won't cause extra reads when checking for the state of some previous value located in a parent collection or is this the only way.
match /Data/{dataDocId}/SubData/{subdataDocId} {
allow get: if request.auth != null
allow create: if request.auth != null
&& get(/databases/$(database)/documents/Data/$(dataDocId)).data.premiumUntill > req.time
}
CodePudding user response:
The billing is per document read (or per successful query). It doesn't matter if you use get()
or other. It is still just one read of dependent document. There is no alternative way to check previous values or check something dynamic. You will have to pay for the reads.
For more information, check this documentations:
CodePudding user response:
If you are reading data from other documents using get()
then you'll be charged the reads. Another way to prevent reads from Firestore rules is to store premiumUntill
in Custom Claims. You'll require a Cloud Function to set custom claims but the best is you can then access premiumUntill from any other Firebase service such as storage and realtime DB if you use any.