title: Query multiple keys on Firebase
body: <p>I'm following Firebase's recommendation of flattening data, but I'm having trouble listing a series of items from my database.</p>
  
  <p>Here's a sample of my database file:</p>
  
  <pre><code>"users" : {
      "UID12349USER" : {
        "firstName" : "Jon",
        "lastName" : "Snow",
        "email" : "jonsnow@winterfell.com",
        "albums" : {
          "UID124ALBUM" : true,
          "UID125ALBUM" : true
        }
      }
  },
  "albums" : {
      "UID124ALBUM" : {
        "name" : "My Artwork",
      },
      "UID125ALBUM" : {
        "name" : "My Sketches",
      }
  }
  </code></pre>
  
  <p>I'm retrieving the list of albums for a given user:</p>
  
  <pre><code>let userAlbums = database.child(usersKey).child(user.uid).child(albumsKey)
  userAlbums.observeSingleEventOfType(.Value, withBlock: { snapshot in
      // fetch [UID124ALBUM: 1, UID125ALBUM: 1]
  })
  </code></pre>
  
  <p>Now I wish I could retrieve all the user's albums in one single query.
  I could do a batch of queries, and populate an asynchronous array, but that doesn't seem like a good approach to me...</p>
  
  <pre><code>for key in albumKeys {
      let album = database.child(self.albumsKey).child(key)
      album.observeSingleEventOfType(.Value, withBlock: { snapshot in
          // fetch album.. append to array
      })
  }
  </code></pre>
  
  <p>Using that approach makes it tricky to detect when the queries have finished, due to the asynchronous nature of the requests. Add to that the fact that some of the requests might fail, due to a bad connection.</p>
  
  <p>Also, if I want to filter one of the albums with a given name (e.g. "My Artwork") or return nil if it doesn't exist, I also end up with a tricky end condition.</p>
  
  <pre><code>var found = false
  
  for key in albumKeys {
      let album = database.child(self.albumsKey).child(key)
      album.observeSingleEventOfType(.Value, withBlock: { snapshot in
          // if current.name == "My Artwork"
          // completion(current)
      })
  }
  // This block will be called before observeSingleEventOfType =.=
  if !found {
      completion(nil)
  }
  </code></pre>
  
  <p>I have a good background on iOS and Swift, but I'm knew to Firebase and NoSQL databases. Can someone point me a good direction? Should I ditch Firebase and try something else? Am I missing some method that can query what I need? Is my json structure wrong and missing some extra keys?</p>
  
  <p>Thanks</p>