ios - Firebase iOS SDK : How to get multiple Data in one query

标签 ios objective-c firebase xcode7

我看过 how to retrieve multiple data in one query firebase所以这可能是一个类似的问题,但我是 Firebase 的新手,我没有正确理解它。

这是我的情况:

我有一个这样的 Firebase 数据库: Database structure

我想检索参加特定事件的用户。
编辑
我试过下面,

Firebase* childrens = [server childByAppendingPath:@"Users"];
    Firebase* firebaseUser = [childrens childByAppendingPath:self.myuserid];
    Firebase* firebaseEvent = [firebaseUser childByAppendingPath:@"Events"];
    Firebase* fbuser= [firebaseEvent childByAppendingPath:@"Created"];
FQuery* query1 = [fbuser queryOrderedByChild:@"id"];
    handleFirebase = [query1 observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot){
        NSEnumerator* childrens = snapshot.children;
        [childrens.allObjects enumerateObjectsUsingBlock:^(FDataSnapshot* rootSnap,NSUInteger rootIndex,BOOL* rootStop){
            NSDictionary* rootData = rootSnap.value;
            NSString* rootKey = rootSnap.key;
            NSLog(@"\nRootKey: %@\nRootData: %@",rootKey,rootData);
        }];


这是 NSLog

2016-03-10 15:27:23.399 SquadApp[4425:110128] 
RootKey: olbuzevent1
RootData: {
    createdTime = "2016-03-08T11:53:33Z";
    name = "OLBUZ event 1";
    participents =     {
        "335e63c9-46c6-4ff8-99e7-1537d99731f7" =         {
            id = "335e63c9-46c6-4ff8-99e7-1537d99731f7";
            joinnedTime = 0;
        };
    };
}
2016-03-10 15:27:24.150 SquadApp[4425:110128] 
RootKey: olbuzevent2
RootData: {
    createdTime = "2016-03-08T12:23:28Z";
    name = "OLBUZ event 2";
    participents =     {
        "335e63c9-46c6-4ff8-99e7-1537d99731f7" =         {
            id = "335e63c9-46c6-4ff8-99e7-1537d99731f7";
            joinnedTime = 0;
        };
    };
}

最佳答案

在 NoSQL 数据库中,您通常必须按照您希望在应用程序中使用数据的方式对数据进行建模。您当前的结构非常适合显示用户组织/参与的事件列表。如果这是您的用例之一,那就太好了。

但是如果您还有一个用例来显示所有参与事件的用户,您可能必须在跟踪该事件的地方添加一个数据结构。

event_users
  eventid1
    uid1: 'participant'
    uid2: 'organizer'
    uid3: 'participant'

这个过程被称为非规范化,在我们的(相当古老的)blog posts 中有介绍。在documentation on structuring data .在最后一页中,您可能还应该阅读 recommendation on nesting .

关于ios - Firebase iOS SDK : How to get multiple Data in one query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912819/

相关文章:

ios - 完成后如何执行方法 UILocalNotification cancelLocalNotification : in iOS 8 or 9

ios - iOS:应用从后台返回后,在访问EAOutputStream时出现SIGPIPE

ios - 如何取消 performBlock :

ios - 类 "ViewController"的重复接口(interface)定义

iPhone RestKit 如何加载本地 JSON 文件并将其映射到核心数据实体?

ios - 在 Storyboard 中以模态序列传递数据?

javascript - 用于 Firebase 规则的 JsonPath

ios - 如何使用storyBoard设置MFSlideviewcontroller的 View Controller ?

ios - Firebase - iPhone X 上的 iOS 应用安装不起作用

firebase - Firebase ImageMagick 的云函数转换 : not found