title: How to retrieve data from Firebase Database?
body: <p>I'm trying to create a simple program that takes name, mobile number and email address from user and then puts the data on Firebase Realtime Database.</p>
  
  <p>There are 3 input boxes and a button which on click does the above operation. Here is the code:</p>
  
  <pre><code>&lt;input type="text" id="name"&gt;
  &lt;input type="text" id="mobile"&gt;
  &lt;input type="text" id="email"&gt;
  
  &lt;button type="button" id="button" onclick="addLead()"&gt;Submit&lt;/button&gt;
  </code></pre>
  
  <p>I've set up Firebase like this:</p>
  
  <pre><code>&lt;script src="https://www.gstatic.com/firebasejs/3.2.0/firebase.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    // Initialize Firebase
    var config = {
      ...
    };
    firebase.initializeApp(config);
  
    var database = firebase.database();
  &lt;/script&gt;
  </code></pre>
  
  <p>And here is my <code>addLead()</code> function:</p>
  
  <pre><code>function addLead() {
      var clientName = document.getElementById('name').value;
      var clientMobile = document.getElementById('mobile').value;
      var clientEmail = document.getElementById('email').value;
  
      var newClientKey = database.ref().child('leads').push().key;
      database.ref('leads/'+newClientKey+'/name').set(clientName);
      database.ref('leads/'+newClientKey+'/mobile').set(clientMobile);
      database.ref('leads/'+newClientKey+'/email').set(clientEmail);
  }
  </code></pre>
  
  <p>This is how I put data to database which works.</p>
  
  <p><a href="https://i.stack.imgur.com/N1zvx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/N1zvx.png" alt="enter image description here"></a></p>
  
  <p>So the <code>newClientKey</code> is generating some string, it works well when inserting but now how to retrieve? The <a href="https://firebase.google.com/docs/database/web/retrieve-data" rel="noreferrer">official documentation</a> is of no help. This generated string might be based on timestamp, if that's the case then generating it again would be impossible.</p>
  
  <p>When retrieving how will I get access to email, mobile and name under that uniquely generated string which was only available at the time of inserting?</p>
  
  <p>Going by the above structure, I need to get 2 levels down to access the required data and because of the lack of documentation, I don't know how to do that, I'm not sure if something like this will work:</p>
  
  <pre><code>database.child().child();
  </code></pre>