0

나는 파이어베이스 동기화 및 인증 기능을 갖춘 앱을 만들기 위해 this 튜토리얼을 따랐습니다. 그러나 이제는 모든 어린이들에게 검색 쿼리를 만드는 방법을 모른다. 왜냐하면이 아이들은 사전 편집 기반 키를 가지고 있기 때문이다. 인증이있는 모든 어린이들에게 firebase 데이터 쿼리하기

이 예에서, 구체적으로는, 모든 "사용자"

{ 
    "users" : { 
    "1e2f048f-a3a0-4190-afad-81d724ed1997" : { 
     "currentCity" : "Arrecifes", 
     "currentCountry" : "ARG", 
     "currentState" : "BSA", 
     "day" : { 
     "domingo" : true, 
     "jueves" : true, 
     "martes" : false, 
     "miercoles" : true 
     }, 
     "gender" : "Masculino", 
     "name" : "Guillermo H Acosta", 
     "position" : "Medio", 
     "registered" : true, 
     "timeSince" : "22:00", 
     "timeUntil" : "23:00", 
     "whereToPlay" : "Güemes" 
    }, 
    "39c6ccf9-61ec-446e-9af3-3a87810fab71" : { 
     "currentCity" : "Alvear", 
     "currentCountry" : "ARG", 
     "currentState" : "CRR", 
     "day" : { 
     "jueves" : true, 
     "miercoles" : true, 
     "viernes" : true 
     }, 
     "gender" : "Masculino", 
     "name" : "Guillermo Acosta", 
     "registered" : true, 
     "timeSince" : "21:00", 
     "timeUntil" : "23:00" 
    }, 
    "4991bdc9-dfc4-4ff5-ab81-0e28f1b3ab53" : { 
     "currentCity" : "Cordoba", 
     "currentCountry" : "ARG", 
     "currentState" : "COR", 
     "day" : { 
     "miercoles" : true, 
     "viernes" : true 
     }, 
     "gender" : "Masculino", 
     "name" : "Hsjja", 
     "timeSince" : "02:00", 
     "timeUntil" : "03:00" 
    }, 
    "509364fd-388b-42ff-91ed-0811811a4ff3" : { 
     "day" : { 
     "jueves" : true, 
     "lunes" : true, 
     "martes" : false, 
     "sabado" : true 
     }, 
     "name" : "Guillermo Acosta", 
     "position" : "Delantero", 
     "timeSince" : "13:00", 
     "timeUntil" : "14:00", 
     "whereToPlay" : "Güemes" 
    } 
    } 
} 
+0

: 모든 사용자의 단지 도시를로드하려는 경우

그래서, 당신은 단지 정보를 포함하는 노드를 유지해야합니다. 실제 JSON을 텍스트로 바꾸십시오. Firebase 데이터베이스 콘솔에서 내보내기 버튼을 클릭하면 쉽게 얻을 수 있습니다. JSON을 텍스트로 사용하면 검색이 가능해 지므로 실제 데이터로 테스트하고이를 사용하여 쉽게 답변 할 수 있습니다. 일반적으로 할 일은 단지 좋은 일입니다. –

+0

제안 해 주셔서 감사합니다. @FrankvanPuffelen 이제 완료되었습니다. –

답변

1

Firebase 데이터베이스를 사용하면 노드를 얻거나 노드를 얻지 못합니다. 쿼리에서 각 노드의 일부를 가져올 방법이 없습니다. 당신은 당신의 문제의 JSON 트리의 사진을 포함 시켰습니다

{ 
    "userCurrentCities" : { 
    "1e2f048f-a3a0-4190-afad-81d724ed1997" : "Arrecifes", 
    "39c6ccf9-61ec-446e-9af3-3a87810fab71" : "Alvear", 
    "4991bdc9-dfc4-4ff5-ab81-0e28f1b3ab53" : "Cordoba", 
    } 
} 
+0

확인. 나는 그것을 염두에 두겠다. 그래서 각 사용자에 대한 노드를 만드는 대신 각 속성에 대한 노드를 만들어야 내 응용 프로그램에 필터가 필요합니까? 내가 맞습니까? –

+1

일반적으로 NoSQL 데이터베이스를 사용하는 경우 앱에서 데이터를 소비하려는 방식으로 데이터를 모델링해야합니다. 훌륭한 소개는 [NoSQL 데이터 모델링] (https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/)에서이 기사를 참조하십시오. –

0

에서 모든 "currentCity을"쿼리 어떻게 이렇게 currentCity 키를 잡아 각 노드를 통해 분석됩니다. currentCity가 NULLABLE 인 경우 별도의 노드에 하우징하는 것이 좋습니다.

let ref = // path to users here 
ref.observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) in 
    // Put all of the users into a dictionary 
    let postDict = snapshot.value as! [String : AnyObject] 
    for user in postDict { 
     // Set each child of the user as a dictionary 
     let data = activity.1 as! [String : AnyObject] 

     // Get the specific child 
     let currentCity = children["currentCity"] as! String 

     // Do something with the data 
     print(currentCity) 
    } 
})