Tyler Rutt
Tyler Rutt

Reputation: 597

Performing a search through database for value

I'm trying to use a search bar, to search for values in my Firebase Database. For example:

---users---
     |
     | ---1412512351--     
     |   |
     |   |- name: Nick
     |   |- age: 37
     |
     | ---5734739374--
     |   |
     |   |- name: John
     |   |- age: 19

When the user finishes typing, and clicks done, I want to perform a search through the database and find the name that they are looking for. Instead of loading all of the users, which could take a while.

Also, I want to get all of the values close to the search. For example if it type "Nick", It should bring up a values close to that string, like Nicholas or Nathan etc.

Thanks in advance!

Upvotes: 0

Views: 88

Answers (1)

Naguib Ihab
Naguib Ihab

Reputation: 4506

To find a particular user (in JS):

var usersRef = new Firebase("https://yourdb.firebaseio.com/users/");
var theNameIAmAfter = usersRef.orderByChild("name").equalTo(SearchByThisName);

Also, I want to get all of the values close to the search. For example if it type "Nick", It should bring up a values close to that string, like Nicholas or Nathan etc...

I'm not sure if that's doable with firebase.

Upvotes: 1

Related Questions