title: Return an Observable by mapping another Observable
body: <p>I am trying to map an observable, get a value from my returned observable then feed this value into another observable and return that result. Here is what I have so far:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>  getJobsByUser(user: User): Observable&lt;Job[]&gt; {
      return this.getUsersGroupsAsObservable(user.uid, 'contacts').map(groups =&gt; {
        groups.map(group =&gt; {
          this.getJobsbyGroup(group.id);
        });
      });
  
    getJobsbyGroup(groupId: string): Observable&lt;Job[]&gt; {
      return this.afs
        .collection&lt;Job&gt;('jobs', ref =&gt; ref.where(`group.${groupId}`, '==', true))
        .valueChanges();
    }
  
    getUsersGroupsAsObservable(
      userId: string,
      type: string = 'users',
    ): Observable&lt;Group[]&gt; {
      return this.afs
        .collection&lt;Group&gt;('groups', ref =&gt;
          ref.where(`${type}.${userId}`, '==', true),
        )
        .valueChanges();
    }
  </code></pre>
  
  <p>The problem is typescript is indicating that my getJobsByUser function will return an observable of type:void. When I do output it on my template I get nothing or undefined. I feel like I need to use switchMap but im a little fuzzy with rx/js. I am unsure how to return an Observable of type Job[]</p>
  
  <p>Update: With help from @Pranay Rana I am now returning array, and can get the first value like this:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>  getJobsByUser(user: User): Observable&lt;Job[]&gt; {
      return this.getUsersGroupsAsObservable(user.uid, 'contacts').pipe(
        mergeMap(groups =&gt; {
          // returns an array of groups - we need to map this
          return this.getJobsbyGroup(groups[0].id); // works with the first value - do we need another map here?
        }),
      );
    }
  </code></pre>
  
  <p><strong>Update 2:</strong> I have managed to get some data back from firestore, but it is emitting multiple observables rather than a combined stream:</p>
  
  <pre class="lang-typescript prettyprint-override"><code>this.fb.getUsersGroupsAsObservable(user.uid, 'contacts')
     .switchMap(groups =&gt; {
        return groups.map(group =&gt; this.fb.getJobsbyGroup(group.id));
     })
      .subscribe(res =&gt; {
         console.log(res);
         // this emits multiple observables rather than one
         this.job$ = res;
      });
  </code></pre>