[英]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.