title: Fetch direct descendants from Firebase Database
body: <p>I have been working on an application lately and have stumbled into yet another problem (that's the life of a programmer, isn't it?). For the record, I am working with the latest versions of Swift, XCode and Firebase. I would like to fetch only the direct descendants of a parent (my reference). Here is my JSON tree:</p>
  
  <pre><code>users
    family-name
      user-1      // I want this...
        pass: abc // but not this ...
      user-2      // ... and this
        pass: def // ... but not this
      events      // I skip this specifically in my code
        event-1
          a: a
          b: b
        event-2
          a: a
          b: b
        event-3
          a: a
          b: b
  </code></pre>
  
  <p>As shown in the tree, I only want to get user-1, user-2, and user-3.</p>
  
  <p>I have tried to use a normal query but it has not worked Instead of getting the ones that I want I also get children values.</p>
  
  <pre class="lang-swift prettyprint-override"><code>let query = userRef.queryOrdered(byChild: "users")
  query.observe(.value, with: { (snapshot) in
    for child in snapshot.children {
      let value = snapshot.value as? NSDictionary
      for anotherChild in value! {
        if "\(key)" == "events" {
          print("Let's skip that, since it's just the events sub-tree!")
        } else {
          // my work goes here
        }
  </code></pre>
  
  <p>I get six values returned to me but I expect two. I have no idea why! Thanks in advance to anyone who can help.</p>