Basically I am writing a search function on a Firestore document field. I want to write equivalent of below SQL. I am not finding solution to proceed.
SELECT * FROM employee WHERE lower(employee_name) LIKE '%johny%';
Basically I am writing a search function on a Firestore document field. I want to write equivalent of below SQL. I am not finding solution to proceed.
SELECT * FROM employee WHERE lower(employee_name) LIKE '%johny%';
There is no like operator. See all available operators at: https://firebase.google.com/docs/firestore/query-data/queries The page also contains different ways on querying the database.
For case insensitive sorting / querying please see the answer at Cloud Firestore Case Insensitive Sorting Using Query
It basically advises to store your lowercase data in an additional field.
As Norman already wrote, there is no LIKE operator in Firebase.
I wrote an answer in SO that explains how to achieve a similar query (even if it is a StartWith search, rather than a full text search):
databaseReference.orderByChild('_searchLastName')
.startAt(queryText)
.endAt(queryText+"\uf8ff")
.once("value")
If you need more advanced ways of searching, then the advice is to use ElasticSearch, as a possible solution.
Cloud Firestore doesn't support native indexing or search for text fields in documents. Additionally, downloading an entire collection to search for fields client-side isn't practical. To enable full text search of your Cloud Firestore data, use a third-party search service like Algolia.
https://firebase.google.com/docs/firestore/solutions/search