簡體   English   中英

Firebase iOS SDK:如何在一個查詢中獲取多個數據

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

我已經看到如何在一個查詢 firebase 中檢索多個數據,所以這可能是一個類似的問題,但我是 Firebase 的新手,我沒有正確理解。

這是我的情況:

我有一個像這樣的 Firebase 數據庫:數據庫結構

我想檢索參加特定活動的用戶。
編輯
我試過,

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'

這個過程被稱為非規范化,在我們的一篇(相當古老的) 博客文章結構化數據文檔中有所介紹。 在最后一頁中,您可能還應該閱讀有關 nesting建議

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM