【问题标题】:How to query based on child dictionary in firebase? Objective C如何根据firebase中的子字典进行查询?目标 C
【发布时间】:2018-04-29 10:22:16
【问题描述】:

好的,我有这个用户数据。这只是我数据库中的众多用户之一。我希望能够获得在“朋友”字典中具有特定键的所有用户。我该怎么做?

我试过了

[[[[ref child:@"Users"]queryOrderedByChild:@"friends"] queryEqualToValue:[my uid]] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {

【问题讨论】:

    标签: objective-c firebase firebase-realtime-database querying


    【解决方案1】:

    您正在使用uid 查询等于值,但您已使用friends 按子级订购; Friends里面的snapshot的值是一个数字,但是你要查询等于key。

    您可以通过调整queryOrderedByChild 以包含您要检查的uid 来做到这一点,并改为查询等于1。查询子路径可以通过将uid 插入到已经包含friends/ 的字符串中来进行,就像[NSString stringWithFormat:@"friends/%@", uid] 一样。

    【讨论】:

    • 您先生,是个巫师。非常感谢
    猜你喜欢
    • 2013-12-21
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    相关资源
    最近更新 更多