title: Using Firebase foreach for querying and traversing
body: <p>I have a Firebase query in Ionic 2 app. This is written in TypeScript. I am trying to retrieve all the users one by one based on a particular <code>familyId</code>.</p>
  
  <p>Since I was not able to do a SQL-query-like for it. I am trying to retrieve one by one and compare it. Below is my code.</p>
  
  <pre><code>var starCountRef = firebase.database().ref('users').orderByChild('familyId');
      console.log("firebase executed");
      //var query = firebase.database().ref("users");
      let familyList: Array&lt;string&gt;;
  
      starCountRef.on("value",(snapshot) =&gt; {
          //console.log('users', snapshot.val());
           var users = snapshot.val();
          console.log("users", users);
  
          snapshot.forEach((childSnapshot) =&gt; {
             var user = childSnapshot.val();
            // console.log("user", user);
            if(user.familyId == familyid){
                      console.log("entered", user);
                      //familyList.push(user.firstName);
                      this.userFamilyList.push(user);
              }
              return false; 
          });
      });
  </code></pre>
  
  <p>I am trying to use arrow functions because of my this references for the list which was failing before when using normal functions. But now <code>snapshot.forEach((childSnapshot))</code>, this returns a boolean according to <a href="https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#forEach" rel="nofollow">Firebase documentation</a> to give a facility to stop emumeration.</p>
  
  <p>So if I remove <code>return false</code> from my code, it gives me a compilation error:</p>
  
  <pre><code>[ts] Argument of type '(childSnapshot: DataSnapshot) =&gt; void' is not
  assignable to parameter of type '(_0: DataSnapshot) =&gt; boolean'.  
  Type 'void' is not assignable to type 'boolean'.
  </code></pre>
  
  <p>How do I handle this condition? Is it only by adding <code>return false</code> or is there any other way to make the callback work without stopping enumerations? Thanks!</p>