3

enter image description here

My firebase is modeled this way. I want to write a query to get userID(simplelogin:1) where email is "test@gmail.com".

Here I want to get key: "simplelogin:1" by searching with it's email address:"test@gmail.com"

I am using firebase SDK for iOS. Can somebody suggest me a query for this? In Javascript or Objective-C

Prajeet Shrestha
  • 7,978
  • 3
  • 34
  • 63

2 Answers2

9

After little messing around I found answer to the question:

Firebase *ref = [_rootReference childByAppendingPath:@"Users"];

[[[ref queryOrderedByChild:@"Email"]queryEqualToValue:@"test@gmail.com" ]
 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
     NSLog(@"%@ Key %@ Value", snapshot.key,snapshot.value);
 }];

There snaphot.key will be the value simplelogin:1 that I wanted.

Prajeet Shrestha
  • 7,978
  • 3
  • 34
  • 63
1

I just want to add one thing on your code Prajeet. I think for the FEventType should be FEventTypeValue, because you're "observing" it once not every time when the child is added.

Firebase *ref = [_rootReference childByAppendingPath:@"Users"];

[[[ref queryOrderedByChild:@"Email"]queryEqualToValue:@"test@gmail.com" ]
 observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
     NSLog(@"%@ Key %@ Value", snapshot.key,snapshot.value);
 }];
Jay
  • 35
  • 1
  • 7