1
votes

If I had 10,000 records and 5 of them have my email and my rules are

allow read: if (resource.email == auth.token.email);

Would I get a result of 5 documents everytime I just straight up read the db.collection('x'):

Would I get charged for 5 or 10,000 reads?

2

2 Answers

3
votes

You are not charged for documents that were not transmitted to the client. If your query returns X documents, you will be billed X reads. Security rules don't change this fact.

You should also be aware that security rules are not filters (please read and understand that link). Any query from a web or mobile client is all or nothing. Security rules will reject access to a query if it doesn't request only documents that would be satisfied by rules. The rules will not check every document to see if it matches the rule - that would not scale at all. Your query needs to include a filter that matches what the rule would check.

2
votes

The rules don't restrict what gets read. Only the query in the code can do that.

If your query only reads the 5 documents that have your email address in their email field, you will be charged for those 5 documents.