I have been using Firebase Real Time Fatabase for a while and I come across Cloud Firestore today. I can't figure out on how to use LIKE operator on Firestore.
Firebase Real Time Database
ref.child('user').orderByChild('name').startAt(name).endAt(name+'\uf8ff')
On Cloud Firestore, I have tried
userRef.where('name', '>=', name); <br> userRef.where('name', '<=', name);
But it doesn't work.
FireSQL is a library built on top of the official Firebase SDK that allows you to query Cloud Firestore using SQL syntax. It's smart enough to issue the minimum amount of queries necessary to the Firestore servers in order to get the data that you request.
It is not possible to use Firebase in this way. Firebase is a real-time object store. It is not a SQL database and is not intended to be a replacement for one. It completely lacks mechanisms such as JOINs, WHERE query filters, foreign keys, and other tools relational databases all provide.
Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group. These queries can also be used with either get() or addSnapshotListener() , as described in Get Data and Get Realtime Updates.
Firestore does not have the concept of server-side joins or projections across collections. Each query or document read can only take data from a single collection, or from all collections that have the same name with collection group queries.
To solve this, you need to change orderByChild
function with orderBy
. So please use the following code:
ref.collection('user').orderBy('name').startAt(name).endAt(name+'\uf8ff')
There isn't an equivalent to LIKE, but you can do prefix filtering in the same way you do it in RTDB.
The query you have written is the same as equals. You need to do the same end by trick and do just less than <
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With