2016-06-03 3 views
0

상황 : 사용자가있는 데이터베이스가 있고, 사용자는 친구를 가질 수 있으며 친구는 현재 사용자 모델을 userID로 연결할 수 있습니다. 따라서 사용자 데이터를로드 할 때 친구들의 Firebase ID 목록을 수신하고 있습니다.Firebase ios : ID로 사용자 목록을 가져옵니다.

질문 : 모든 사용자가 동시에 firebase 스냅 샷을 수신 할 수있는 방법이 있습니까? 적합한 솔루션을 찾지 못했습니다. .child()가 하나의 객체와 직접 연결되어 있으며 queryOrderedByChild() 및 queryOrderedByValue()가 그러한 요청을하지 않는 것으로 보입니다.

조언이 필요하면 감사드립니다.

편집 : 데이터베이스 구조 :

{ 
    "Users": { 
     "user_id_first" : { 
      "user_info" : { 
       "name": "name", 
       "age": "age" 
      }, 
      "friends": {} 
     }, 

     "user_id_second" : { 
      "user_info" : { 
       "name": "name", 
       "age": "age" 
      }, 
      "friends": {} 
     }, 

     "user_id_third" : { 
      "user_info" : { 
       "name": "name", 
       "age": "age" 
      }, 
      "friends": { 
       "user_id_first" : true, 
       "user_id_second" : true 
      } 
     } 
    } 
} 

실제로 중포 기지 사용자의 ID입니다 친구 아이디의 목록이 있습니다. 내가 필요로하는 모든 friendsId에 액세스 할 수 루프

myDBRef.child("Users").child("friend_id") 
+1

이미 수행 한 작업과 중단 된 위치를 보여주는 최소한의 JSON (텍스트, 스크린 샷 없음)을 보여주십시오. 그것 없이는 도움이 어려울 것입니다. –

답변

0

사용처럼 각 친구에 대한 새로운 기준을 만들지 않고 (즉, 하나의 참조를 사용) 한 중포 기지 스냅 샷에이 사용자에 대한 정보를 검색 할 수 있습니다 : -

let parentRef = FIRDatabase.database().reference().child("Users") 
    parentRef.child(FIRAuth.auth()!.currentUser!.uid).child("friends").observeEventType(.Value, withBlock: {(snapshot) in 

    if snapshot.exists(){ 

    if let friendsDictionary = snapshot.Value as! NSMutableDictionary{ 

       for each in friendsDictionary as! [String : AnyObject]{ 

        let friendsId = each.0 as! String 

        parentRef.child(friendId).observeEventType(.Value, withBlock: {(friendDictionary) 

        if let friendsInfo = friendDictionary.Value as! NSMutableDictionary{ 
          //retrieve the info 
       } 
      }) 
      } 
     } 
    } 
}) 
+0

문제가 해결 되었습니까? – Dravidian

+0

나는 같은 접근법을 생각하고 있었지만 이것을 해결하는 좋은 방법입니까? 나는 성능에 대해 어떻게 생각하니? –

관련 문제