【问题标题】:How to get a keyname by its nested values in firebase?如何通过其在firebase中的嵌套值获取键名?
【发布时间】:2015-03-29 14:13:58
【问题描述】:

我的 firebase 就是这样建模的。我想写一个查询来获取用户 ID(simpllogin:1),其中电子邮件是“test@gmail.com”。

在这里我想通过搜索它的电子邮件地址来获取密钥:“simplelogin:1”:“test@gmail.com”

我正在使用适用于 iOS 的 firebase SDK。有人可以建议我对此进行查询吗?在 Javascript 或 Objective-C 中

【问题讨论】:

  • 如何以这种方式存储数据???请指导我

标签: ios objective-c firebase livechat firebasesimplelogin


【解决方案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);
 }];

【讨论】:

    【解决方案2】:

    经过一番折腾,我找到了问题的答案:

    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。

    【讨论】:

    • 一旦 Stack Overflow 允许,请务必接受您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2021-12-14
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    相关资源
    最近更新 更多