title: Retrieve data from Firebase database in JavaScript
body: <p>I am new to Firebase, and I am trying to figure out how to retrieve data from my Firebase database. I was able to add to it successfully based on a user's unique id (<code>uid</code>), but now getting data from it seems to be incredibly difficult. I want to grab the first name from the current user ('user' in the following code), but this JavaScript doesn't seem to be working:</p>
  
  <pre><code>var uid = user.uid
  firebase.database().ref('users/' + uid).on('value', function(snapshot) {
      this.first_name = snapshot.val().first_name;
  });
  </code></pre>
  
  <p>As soon as I make the call to <code>this.first_name</code>, it gives me the following error: </p>
  
  <blockquote>
    <p>FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot set property 'first_name' of null.</p>
  </blockquote>
  
  <p>In case it helps, my database is structured like this:</p>
  
  <pre><code>{
    users: {
      "uid1": {
        first_name: "John"
      },
      "uid2": {
        first_name: "Sue"
      }
    }
  }
  </code></pre>