How to Perform SQL "Like" Operation on Firebase

How to do sql like query in firebase?

There is no like query in firebase realtime database. The following queries are the ones that you can use:

Method              Usage
queryOrderedByKey Order results by child keys.
queryOrderedByValue Order results by child values.
queryOrderedByChild Order results by the value of a specified child key or nested child path.

https://firebase.google.com/docs/database/ios/lists-of-data#sort_data

To solve your problem, you can change your database to the following:

users
pushId
name : peter
employment : programmer
group : teachProg
pushId
name : john
employment : teacher
group : teachProg

And then use queryOrderByChild("group").queryEqualToValue("teachProg") and you will be able to retrieve all users that are programmers or teachers

How to write a query in Firebase like SELECT * FROM table WHERE status = '1'

According to your snapshot, this should work

var userId = firebase.auth().currentUser.uid;
return firebase.database().ref('/tutor/' + userId).once('value').orderBy('approve_status')
.equalTo('1').then((snapshot) => {
console.log(snapshot.val().bio);
// Data you want...
});

Try the firebase documentation to get more idea about queries here

dart: get SQL like %text% search from firebase database snapshot

You are looking for a contains query, but Firebase doesn't provide that. You can refine your actual query by looking for values that are equalTo or endAt or startAt (these methods are available to you as well). Making three requests is going to be costly, though.

If your database is not large and your data is not sensitive, I suggest fetching the whole data and making a client-side filter as shown here.



Related Topics



Leave a reply



Submit