Home > Software design >  What is index entry on firestore?
What is index entry on firestore?

Time:10-26

I am tring to use COUNT() method on firestore which release weeks ago and pricing is base on index entry, But what is index entry? Assume that I have thousands documents in a single collection like this without composite index, Just default index for each fields.

nickname: Jack
age: 28
score: 72

Then run query like this

Query query = collection.whereEqualTo("score", "72").count().get().get();

I am getting like 1 index entry no matter what amount of documets matches?

CodePudding user response:

An index is essentially a sorted list. When you are querying whereEqualTo("score", "72"), Firestore will use the default index created for score field.

I am getting like 1 index entry no matter what amount of documents matches?

As mentioned in the pricing documentation, there is a minimum charge of one document read even if no index entry matches the query. Thereafter, it totally depends on the number of index entries that match your query. For example, if there are 34553 documents with score equal to 72, then that cost you 35 reads:

const reads = Math.floor(34553/1000)   1 // 35
  • Related