Firestore Comparison Operators - contains, does not contain, starts with

From the documentation "...The where() method takes three parameters: a field to filter on, a comparison operation, and a value. The comparison can be <, <=, ==, >, or >=..."

The queries that we need to carry out are:

  • equals (==)
  • not equal to (???)
  • less than (<)
  • greater than (>)
  • less than or equal (<=)
  • greater than or equal (>=)
  • contains (???)
  • does not contain (???)
  • starts with (???)

In this question the suggestion is to implement a full text search such as Elastic or Algolia. I don't need full text search - I just need these basic operators to search in nominated fields. But the bigger problem I have is that my app is off-line for substantial periods of time and we cache the data we need off-line and off-line full text search is not an option (except if you get the Enterprise ($$$$$$) license of Algolia - but still seems like overkill for what we are looking for).

Do any of you have any solutions for where("FIELD", "???", "string") when "???" is "not equal to", "contains", "does not contain", or "starts with"?

Any ideas gratefully appreciated.


There are no native "contains", "does not contain", "starts with" or "ends with" queries in Cloud Firestore.

You can approximate a very limited "starts with" query using < and >, however:

// All names starting with "Sa"
db.collection("people")
  .where("name", ">", "Sa")
  .where("name", "<", "Saz")

Firestore has added the "array-contains" query operator. This now means that we can store a deconvoluted version of the field as an array of sub-strings, then use the "array-contains" operator. See:

https://github.com/googleapis/nodejs-firestore/releases/tag/v0.16.0