title: Firebase,Swift: Retrieving only those `autoID` node's which have a specific key
body: <p><strong>Question---></strong></p>
  
  <ol>
  <li><p>Is there a way to retrieve a node whose key is an  <code>autoID</code>, which <strong>Might</strong> contain a particular key. Like in below JSON structure i have a child node <code>powers</code> inside some <code>autoID</code>'s, <em>not all of them</em>, I want to retrieve only those nodes which have key <code>powers</code> in them not knowing what corresponding <code>value</code> might be . </p></li>
  <li><p>In the below two suggested approach which one would <strong>consume less BandWidth</strong>? </p></li>
  </ol>
  
  <p><em>My JSON Tree</em></p>
  
  <pre><code>node1   
    -node12  
      -autoId1  
  
          expo: "5122223333"
          users:   
              -MqrvHRBTRcPzrvAOdkklBzeFW7E2  
                  firstName: "Margery"  
                  lastName: "Lady" 
      -autoId2  
          powers: "Triple3"
          expo: "2123338983"
          users:   
              -LqrsadaDs12BTRcPzrvABzeFW7E2  
                  firstName: "Tyrion"  
                  lastName: "Imph"
    -node21  
      -autoId3  
          powers: "Triple"  
          expo: "5123333"
          users:   
              -MqrvHRBTRcPzrvAOdkklBzeFW7E2  
                  firstName: "Cersie"  
                  lastName: "Lady" 
      -autoId4  
          powers: "Quad"  
          expo: "2128983"
          users:   
              -LqrsadaDs12BTRcPzrvABzeFW7E2  
                  firstName: "Sansa"  
                  lastName: "Lady"  
  </code></pre>
  
  <p><strong>What Have I Tried---></strong></p>
  
  <ul>
  <li><p>Retrieve the entire <code>node12</code> and then checking which of the <em>autoId</em>'s have a particular <code>key</code>. for eg lets say powers: "Triple3"</p>
  
  <pre><code>let prntRef = FIRDatabase.database().reference().child("node1").child("node12")
  prntRef.observeSingleEventOfType(.Value, withBlock: {(snap) in
  
    if snap.exists(){
  
       for each in snap.value as! [String:AnyObject]{
  
               prntRef.child(each.0 as! String).child("powers").observeSingleEventOfType(.Value, withBlock: {(IMsnap) in
  
             if IMsnap.exists(){
  
                  //Found The correct node
                  }
              })
          }
        }else{
  
           //
          }
     })
  </code></pre></li>
  <li><p>My other alternative solution is:- </p>
  
  <pre><code>FIRDatabase.database().reference().child("node1").child("node12").queryOrderedByChild("powers").observeSingleEventOfType(.Value, withBlock: {(snap) in
  
     if let snapDict = snap.value! as? [String : AnyObject]{
  
             print(snapDict.keys.first!)   //Retrieving My AutoID .Nut this gives me entire node. 
  
          }
  
          for each in snap.value as! [String:AnyObject]{
  
               print(each.0)   //Retrieving My AutoID 
  
         }
     })
  
  })
  </code></pre></li>
  </ul>
  
  <p><strong>Note:-</strong> I found somewhat similar Q posted in Firebase forum, but no one seems to answer it :-<a href="https://groups.google.com/forum/#!topic/firebase-talk/ZDHKwxRMiKQ" rel="nofollow">https://groups.google.com/forum/#!topic/firebase-talk/ZDHKwxRMiKQ</a></p>