Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get user email from Firebase with query

Tags:

firebase

I want to implement search by email in my app but kinda stuck with the design of query. my data structure looks like this

users {
      uid {
          email: [email protected] 

i tried the following query:

console.log(reqestEmail); // proper email here
new Firebase(USERS)
  .startAt(reqestEmail)
  .endAt(reqestEmail)
  .once('value', function(snap){
     var foundUser = snap.val();

     console.log(foundUser) // output is null
    });

I guess the problem is in the fact i have a uid in the path. But how to to implement search with this data structure — if i this uid is the needed result?

If it is important using Firebase 2.0.2 and AngularFire 0.9

Sorry guys: noob here. Also in danger of suspention of account.

like image 551
walkthroughthecode Avatar asked Nov 25 '14 21:11

walkthroughthecode


1 Answers

You have to first order by email address, so that you can then filter on it:

console.log(reqestEmail); // proper email here
new Firebase(USERS)
  .orderByChild('email')
  .startAt(reqestEmail)
  .endAt(reqestEmail)
  .once('value', function(snap){
     var foundUser = snap.val();
     console.log(foundUser) // output is correct now
  });

Working sample in this jsbin: http://jsbin.com/fenavu/2/edit?js,console

like image 74
Frank van Puffelen Avatar answered Jan 01 '23 11:01

Frank van Puffelen