title: firebase - get all chat rooms for a member
body: <p>I'm integrating multi-room chat in my app and I'm stuck with getting a list of all chat room a specific user is member of.</p>
  
  <p>The structure looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/xsrM6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xsrM6.png" alt="members structure"></a></p>
  
  <p>The rooms and members are created with <em>childByAutoId</em> like this:</p>
  
  <pre><code>FIRUser *user = [FIRAuth auth].currentUser;  
  mdata[@"uid"] = user.uid;
  
  roomKey = [[_rootRef child:@"messages"] childByAutoId].key;
  
  NSString *memberID = [[[_rootRef child:@"members"] child: roomKey ] child: user.uid ].key;
  
  // set Meta data for member to be able to recognize later
  
  [[[[_rootRef child:@"members"] child: roomKey ] child: memberID ] setValue:mdata];
  </code></pre>
  
  <p>Now I'm trying the get the list of rooms for a (hard coded) user like that:</p>
  
  <pre><code>-(void) getRoomKeys {
  
      [[[[_rootRef child: @"members"] queryOrderedByChild:@"uid" ] queryEqualToValue:@"QLfRoGpoCjWpzira7fljBj8g3EJ3"]
       observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
           NSDictionary&lt;NSString *, NSString *&gt; *message = snapshot.value;
       }];
    }
  </code></pre>
  
  <p>This return 0 key/value pairs.</p>
  
  <p>When I take out the query I get all room keys. When I change the structure to this
  <a href="https://i.stack.imgur.com/GrX9a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GrX9a.png" alt="uid one level higher "></a></p>
  
  <p>I will get all rooms for that user but with this structure I can't add other members to that room. So I need to dig one level deeper.</p>
  
  <p>So how to set the query for nodes that have been created by childByAutoId?</p>
  
  <p>Thanks for your help!</p>