title: Getting promise from a nested forEach loop?
body: <p>I'm trying to loop through a Firebase List (using AngularFire2), and I want to get a Promise to indicate when the nested loops completed so I can process on the second action. I'm using the following code:</p>
  
  <pre><code>  console.log('START');
    this.af.database.list('Sites/123123/Users')
      .map(users =&gt; {
        users.map(user =&gt; {
          console.log('found a user ', user);
          this.af.database.list('registeredUsers/' + user.$key + '/Sites')
            .forEach(sites =&gt; {
              sites.forEach(site =&gt; {
  
                if (site.$value == '123123') {
                  console.log('found site ', site.$key);
                }
              });
            });
        });
      }).first().toPromise().then(function (x) {
        console.log('ALL DONE')
      });
  </code></pre>
  
  <p>The output is:</p>
  
  <p><img src="https://i.stack.imgur.com/gQJkV.png" alt="console output"></p>
  
  <p>But I'm getting the Promise only after the outer loop, without waiting for the nested loop to complete. Any suggestions?</p>