0

Let's say I wanna check if there is a localized document in EN in my Firestore. I will try to read:

DocumentSnapshot englishDocument = _firestore.document('/books/000000/lang/en').get();

Then I check if the document exists. If it doesn't check whether the book exists in Spanish.

if (!englishDocument.exists) {
      DocumentSnapshot spanishDocument = _firestore.document('/books/000000/lang/es').get();
    }

Now 3 scenarios:

- The book is available in EN: I get billed for 1 read

- The book is NOT available in EN but it is in ES: Do I get billed for 1 or 2 reads?

- The book is NOT available in neither of the two languages: Do I get billed for 2 reads or does it count as 0 reads?

Community
  • 1
  • 1
Tomas Baran
  • 1,570
  • 2
  • 20
  • 37

1 Answers1

2

Calling get() to read a document costs 1 read operation in all situations. There is no way to check to see if a document exists without paying the cost of that read. You are essentially paying for the privilege of using a massively scalable index to quickly tell you about the document.

Please see the documentation about minimum charges for queries:

There is a minimum charge of one document read for each query that you perform, even if the query returns no results.

See also: How to check if a document exists with a given id in firestore, without costing money?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441