Search code examples
google-cloud-firestoredocument-database

Is it faster to query a string or a boolean in Firestore?


I'm trying to structure schema for a document database. I'm using Google Cloud Firestore. I want my data to be queried easily and quickly, so I'm keeping the structure shallow or flat. Will queries run faster querying for booleans or strings.

{ side: 'left' } //string

   Which one is faster to query?

{ left: true } //boolean

Solution

  • Practically speaking: It doesn't matter.

    All fields in Cloud Firestore are indexed on the server, and the amount of time needed to search for a boolean value vs a string within that index would not be noticeable -- particularly compared to the time required to download some documents over a network.

    Instead, go with the value that makes the most sense for your application. And, while we're on the topic, don't mix data types in the same field. That will make things harder to query.