简体   繁体   English

Firebase iOS SDK:如何在一个查询中获取多个数据

[英]Firebase iOS SDK: How to get multiple Data in one query

I've seen how to retrieve multiple data in one query firebase so this might be a similar question, but I'm new to Firebase and I don't get it properly.我已经看到如何在一个查询 firebase 中检索多个数据,所以这可能是一个类似的问题,但我是 Firebase 的新手,我没有正确理解。

Here is my situation:这是我的情况:

I have a Firebase database like this:我有一个像这样的 Firebase 数据库:数据库结构

I want to retrieve users who participated in a particular event.我想检索参加特定活动的用户。
EDIT编辑
i tried bellow,我试过,

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);
        }];


here is NSLog这是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;
        };
    };
}

In a NoSQL database you often have to model the data for the way you want to use it in your application.在 NoSQL 数据库中,您通常必须根据您希望在应用程序中使用数据的方式对数据进行建模。 Your current structure is great for showing a list of events that the user organized/participated in. If that is one of your use-cases, that is great.您当前的结构非常适合显示用户组织/参与的事件列表。如果这是您的用例之一,那就太好了。

But if you also have a use-case to show all users that participated in an event, you'll likely have to add a data structure where you track that.但是,如果您还有一个用例来显示参与活动的所有用户,您可能需要添加一个数据结构来跟踪它。

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

This process is known as denormalization and is covered in one of our (quite old) blog posts and in the documentation on structuring data .这个过程被称为非规范化,在我们的一篇(相当古老的) 博客文章结构化数据文档中有所介绍。 In that last page you should probably also read the recommendation on nesting .在最后一页中,您可能还应该阅读有关 nesting建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS Firebase SDK上查询条件复杂的数据 - Query data with complex condition on iOS Firebase SDK 如何在一个iOS应用程序查询中从单个sqlite数据库的多个表中获取数据? - How to get data from multiple tables from single sqlite database in one query for iOS application? 如何在Firebase的iOS SDK上执行分页查询? - How do I perform a pagination query on Firebase's iOS SDK? 如何在最新的 Firebase IOS SDK 中获取 Firebase JWT 令牌以在服务器端进行验证 - How to get Firebase JWT token to validate on server side in Latest Firebase IOS SDK 如何从查询中保存数据,在字符串数组中,Firebase iOS? - How to save data from query, in array of string, Firebase iOS? 如何从iOS上的Facebook SDK获取用户数据 - how to get user data from Facebook SDK on iOS Firebase iOS-使用复合键的一部分进行查询 - Firebase iOS - Query with one part of the compound key 如何在一个块中从Firebase查询中获取所有结果 - How to get all results from a Firebase Query in one block 如何在 iOS 上显示使用 firebase-cpp-sdk 收到的 FCM“数据”消息? - How to display FCM 'data' message received using firebase-cpp-sdk on iOS? 如何从 iOS 中的 Firebase FCM 推送通知获取数据 - How to get data from Firebase FCM push notification in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM