我的firebase以这种方式建模。我想编写一个查询来获取userID(simplelogin:1),其中email是“test@gmail.com”。
在这里,我想获得密钥:“simplelogin:1”,用它的电子邮件地址搜索:“test@gmail.com”
我正在使用适用于iOS的firebase SDK。有人可以建议我查询吗?在Javascript或Objective-C
答案 0 :(得分:9)
在一点点搞乱之后,我找到了问题的答案:
Firebase *ref = [_rootReference childByAppendingPath:@"Users"];
[[[ref queryOrderedByChild:@"Email"]queryEqualToValue:@"test@gmail.com" ]
observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@ Key %@ Value", snapshot.key,snapshot.value);
}];
snaphot.key将是我想要的值simplelogin:1。
答案 1 :(得分:1)
我只想在你的代码Prajeet上添加一个东西。我认为FEventType应该是 FEventTypeValue ,因为你每次添加孩子时都不会“观察”它。
Firebase *ref = [_rootReference childByAppendingPath:@"Users"];
[[[ref queryOrderedByChild:@"Email"]queryEqualToValue:@"test@gmail.com" ]
observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot) {
NSLog(@"%@ Key %@ Value", snapshot.key,snapshot.value);
}];