Firestore comparison operators - contains, does not contain, starts with

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

The queries we need to fulfill are:

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

This question suggests implementing a full-text search such as Elastic or Algolia. I do not need a full text search. I just need these basic operators to search in nominated fields. But the big problem is that my application is disconnected for significant periods of time, and we cache the data we need offline, and offline full-text search is not an option (except when you get Enterprise ($$ $$$ $) Algolia licenses - but still seems redundant for what we are looking for).

Any of you have any solutions for where ("FIELD", "???", "string"), when "???" “not equal”, “contains”, “does not contain” or “begins with”?

Any ideas gratefully appreciated.

+12
google-cloud-firestore
source share
2 answers

There are no built-in "contains", "does not contain", "starts with" or "ends" 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") 
+8
source share

A request statement "array contains" has been added to Firestore. Now this means that we can save the deconvolution of the field version as an array of substrings, and then use the array-containing operator. See:

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

0
source share

All Articles