title: How to query for existence of child array in Firebase?
body: <p>Hello Internet Denizens,</p>
  
  <p>I'm using Firebase at the moment and am trying to query the following structure:</p>
  
  <pre><code>items
    1
      - name: "Car"
      - Children
        - 2
        - 3
    2 
      - name: "Wheels"
    3 
      - name: "Engine"
  </code></pre>
  
  <p>You can see from this example that I have an array of items with Ids of 1,2, &amp; 3.  1 also has its own sub-array called Children, which is composed of Ids 2 &amp; 3.  </p>
  
  <p>How would I make a firebase query that pulled back only the Ids which had an array called children?</p>
  
  <p>At first, I thought something like the following would work:</p>
  
  <pre><code>&lt;my firebase path&gt;.child('items').orderByChild('Children').once('value', function(snap){
      // ... No results :(
  });
  </code></pre>
  
  <p>No luck.  Next, I tried adding an attribute called hasChildren = true to the Id of 1 and then queried like so.</p>
  
  <pre><code>&lt;my firebase path&gt;.child('items').orderByChild('hasChildren').equalTo(true).once('value', function(snap){
      // ... iterate over results, which in this case is the Id 1
  });
  </code></pre>
  
  <p>However, when I do a snap.ForEach(function(data)... and then look at data.val().Children, it's just a blank result, which confuses me because I thought Firebase pulled back all child nodes.  Hence, the need to flatten your data.</p>
  
  <p>How do I get those Children values?</p>
  
  <p><b>** Update ** Plunker Added </b></p>
  
  <p><a href="http://plnkr.co/edit/9U0ujEwdKi7sgQGmd6IE?p=preview" rel="nofollow">http://plnkr.co/edit/9U0ujEwdKi7sgQGmd6IE?p=preview</a></p>
  
  <p>Looks like this was a comedy of errors.  </p>
  
  <p>1) In the simple example, 1, 2, &amp; 3 are ordered, so firebase treats it as an array.  In the real world, those numbers are much more random so firebase treats them as an object since they aren't ordered.
  <p>
  2) For some reason, Intellij wasn't showing the Children object's contents. I had to type in something like data.val().Children['3'] to get a value or something like for(var property in data.val().Children) to iterate through the fields.  Weird.
  <p>
  3) I <b>STILL</b> can't do .child('items').orderByChild('Children') ... since that returns all records.  Oddly enough, however, it returns the ones that have Children first.</p>