title: How to retrieve desired JSON object from firebase database in JSON formate using Node js
body: <p>I m new to Node js and firebase.
  I m trying to fetch JSON data stored in my firebase database depending upon some search criteria.</p>
  
  <p>In the following example:</p>
  
  <p><img src="https://i.stack.imgur.com/pCYHT.png" alt="See this Image"></p>
  
  <p>The variable childname is key to whose value we have to search (col1) and findvalue is value for that key( value for col1 to be)</p>
  
  <p>for this I tried  the following codes:</p>
  
  <pre><code>function searchKeyValue(headNode,childname,findvalue) {
    var ref = firebase.database().ref("data/"+headnode);
    ref.orderByKey().on("child_added", function(snapshot) {
      //extracting Query
      ref.orderByChild(childname).equalTo(findvalue).on("value",function (snapshot) {
        console.log(snapshot.val());
      });//end of Query
    });//end oder by key
  }// end of function 
  </code></pre>
  
  <hr>
  
  <pre><code>function searchKeyValue(headnode,childname,findvalue) {
    var ref = firebase.database().ref("data");
    nextref=ref.child(headnode);
    nextref.orderByChild(childname).equalTo(findvalue).on("value",function (snapshot) {
      console.log(JSON.stringify(snapshot.val()));
    })
  }
  </code></pre>
  
  <p>but both fails to provide me the desired output:
  OUTPUT DESIRED is :</p>
  
  <pre><code>{1:"152",2:"233.69",3:"-191.7",4:"133.69",5:"-199.769",6:"AMUKH",7:"4",{"port":4},8:"NTP",9:{"Dup":12345}]}
  </code></pre>
  
  <p>But getting:</p>
  
  <pre><code>{"-KOZ2Md3NZ_vWddAIBj3":[null,"152","233.69","-191.7","133.69","-199.769","AMUKH","4",{"port":4},"NTP",{"Dup":12345}]}
  </code></pre>
  
  <p>[Note: I missed all keys of my saved data I m getting only values to that keys...]</p>