2016-08-27 3 views
0

'Firebase'에서 한 번에 배열의 여러 문자열을 쿼리하는 방법에 대한 아이디어가 있다면 궁금합니다. 기본적으로 쿼리는 조건을 사용합니다. 나는 수백 가지 방법으로 데이터를 재구성 해 보았지만 나에게는 아무런 효과가 없었다. 또한 모든 데이터를 덤프하고 쿼리를 수행 한 후 배열에 일치시킬 데이터가 너무 많습니다. 어떤 도움이나 제안이라도 대단히 감사하겠습니다.Firebase 쿼리 문자열 배열

var uniqueStoreId = [“1”, “2”, “3”, “4”, “5”, “6”] 
var posts = [Post]() 

ref.queryOrderedByChild("storeId").queryEqualToValue("\(uniqueStoreId)").observeEventType(.Value, withBlock: {snapshot in 
        if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] { 
         for snap in snapshot{ 
          if let postDict = snap.value as? Dictionary<String, AnyObject> { 
           let key = snap.key 
           let post = Post(postKey: key, postData: postDict) 
           self.posts.insert(post, atIndex: 0) 
          } 
         } 
        } 

     }) 
+0

중포 기지의 쿼리 기능을 즐길 수 있습니다. 때로는 다중 값 쿼리를 허용하는 방식으로 값을 결합 할 수 있지만 항상 그런 것은 아닙니다. [주제에 대한이 답변] (http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase)을 참조하십시오. –

답변

0

가 // 같은 것을 할 .. 그 배열 또는 dictioary 여부, 다음의 요구 사항에 따라 사용 후, 하나 개의 배열에 추가하고 확인 단 하나의 조건을 허용

    var arrMessage = [MessageFirebase]() 

        if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] { 

         //If its a Array then use below method 
         for snap in snapshots { 
          if let postDictionary = snap.value as? Dictionary<String, AnyObject> { 
           let key = snap.key 
           let message = MessageFirebase(key: key, dictionary: postDictionary) 
           // Items are returned chronologically, but it's more fun with the newest jokes first. 

           //if needed 
           arrMessage.insert(message, atIndex: 0) 
          } 
         } 

         //If its a dictionary then use below method 
         if !(arrMessage.count > 0) { 
          let key = snapshot.key 
          let message = MessageFirebase(key: key, dictionary: snapshot.value!) 
          // Items are returned chronologically, but it's more fun with the newest jokes first. 

          //if needed 
          arrMessage.insert(message, atIndex: 0) 
         } 
        }