Search code examples
firebasegoogle-cloud-firestorefirebase-security

Firestore Security Rules read count on get() document


I have to check a document value != a string value in the Firebase Security rules. So I have to first check if the document exists and then check the value.

allow read: !get(path).data || get(path).data.value !== 'xyz';

As I am calling the get() method twice, will it count 2 reads? If yes, how can I write the logic so that I fetch the document data once and reuse it?


Solution

  • As per the documentation, you are only charged once.

    You are only charged one read per dependent document even if your rules refer to that document more than once.