Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To query a string property value for text search in Google Firestore, you can use the "where" method with a "like" operator. Here's an example:

db.collection("myCollection")
  .where("myProperty", ">", "")
  .where("myProperty", "<", "\uf8ff")
  .where("myProperty", "like", "searchText")
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      console.log(doc.data());
    });
  });

In this example, "myCollection" is the name of the collection, "myProperty" is the name of the string property you want to search, and "searchText" is the text you want to search for.

The first two "where" statements ensure that only documents with a non-empty "myProperty" value will be returned. The "\uf8ff" character is the highest possible Unicode character, ensuring that any string that comes after it in the alphabet will also be included in the search.

The "like" operator with the "searchText" value allows you to search for any document that contains "searchText" as a substring in "myProperty".

Finally, the "get" method executes the query and returns a query snapshot, which you can loop through to access each matching document's data.