WhaSukGO
WhaSukGO

Reputation: 703

What exactly is regarded as 'document read' in Cloud Firestore?

I did find some posts about how pricing is decided, but I want to make it as clear as possible.

Here's my document structure,

{
 ...
 firstOption: "A",
 secondOption: "B",
 customerID: "1234",
 ...
}

I need to check if any of three conditions is met.

For example, if firstOption is "A", secondOption is "B", or customerID is "1234".

Since Firestore doesn't support OR in where cluase, my current plan is,

db.collection('').get().then(snapshot => snapshot.filter(doc => { 
 const {firstOption, secondOption, customerID} = doc.data();

 if(firstOption === 'A' || secondOption === 'B' || customerID === '1234') 
  return true;
 else 
  return false;    
})

If three documents are returned, is it regarded as reading three documents or, since no where clause is used to filter, reading the entire documents in the collection?

Upvotes: 0

Views: 35

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

If you write client code that queries a collection and doesn't filter any documents, it will read every document in that collection so that the client can access all their snapshots. In general, if a query matches a document, it will count as a read.

Upvotes: 1

Related Questions