Search code examples
iosobjective-cfirebaselivechatfirebasesimplelogin

How to get a keyname by its nested values in firebase?


enter image description here

My firebase is modeled this way. I want to write a query to get userID(simplelogin:1) where email is "[email protected]".

Here I want to get key: "simplelogin:1" by searching with it's email address:"[email protected]"

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


Solution

  • After little messing around I found answer to the question:

    Firebase *ref = [_rootReference childByAppendingPath:@"Users"];
    
    [[[ref queryOrderedByChild:@"Email"]queryEqualToValue:@"[email protected]" ]
     observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
         NSLog(@"%@ Key %@ Value", snapshot.key,snapshot.value);
     }];
    

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