4
votes

Following is one of the examples in Cloud Firestore list query

citiesRef.where("state", ">=", "CA").where("state", "<=", "IN")

What does it mean?

Is this the way I can do a query for searching substrings. For example, I have a collection of users and all my user documents have first_name and last_name. Now as a user I am trying to search others by typing a portion of the name and searching. I should be able to write a query to get all user who's name contains that string. How do I do that in Firestore?

1
If you have two different questions that are not related to each other, please ask them separately so they can be more easily answered separately. - Doug Stevenson
Sorry for my wordings. The topics are related. Now I this its better to understand. - Tapas Mukherjee
I have to agree. I came here with your second question looking for answers. If someone happens to answer both questions, fine, but it would really be better to ask two separate questions. Yes, they are related, but they are not the same question. - Methodician

1 Answers

4
votes

[Googler here] To answer your first question, state <= "IN" is a query for all documents where the value of the state property sorts less than or equal to the value "IN". So if the state was "IM" that would be true but not if it was "IO" or "IP" as those come later lexicographically.

The use of "IN" may have been confusing here, it's meant to be the abbreviation for the state of Indiana but it's also a reserved word in many other database systems.

To answer the second question, Cloud Firestore does not support any native "contains", operations or other common string queries like "beginsWith", "endsWith", "like", etc. The reason for this is that all Cloud Firestore queries must hit an index and right now we don't index textual fields in a way that would make those queries fast.

Currently we recommend using a third-party search provider like Algolia, and we provide some guidance on doing so here: https://firebase.google.com/docs/firestore/solutions/search