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
How to Concatenate and Minify Multiple CSS and JavaScript Files with Grunt.Js (0.3.X)
How to Make Changeable Themes Using CSS and JavaScript
Dynamically Expand Height of Input Type "Text" Based on Number of Characters Typed into Field
Disable Images in Selenium Python
Can Jquery Change CSS Style Definition? (Not Individual CSS of Each Element)
Get/Set Current @Keyframes Percentage/Change Keyframes
Google Map Custom Marker with CSS Rounded Corner
Span Inside Button, Is Not Clickable in Firefox
Call Java Function from JavaScript Over Android Webview
Polymer Share Styles Across Elements
Serving Gzipped CSS and JavaScript from Amazon Cloudfront via S3
Screen Styling When Virtual Keyboard Is Active
How to Use JavaScript to Check and Load CSS If Not Loaded
Jquery or JavaScript - How to Disable Window Scroll Without Overflow:Hidden;
How to Get the Coordinates of a Mouse Click on a Canvas Element
React: "This" Is Undefined Inside a Component Function