I'm currently facing a challenge that involves retrieving both administrators and professionals from the "users" collection using AngularFire's latest version. I am utilizing Observables for this task.
My goal is to make two parallel requests and combine the results of administrator and professional users into one response. I attempted to achieve this using the forkJoin operator as shown below:
getUsers(): Observable<any> {
return forkJoin([
this.afs.collection('users', ref => ref.where('roles.admin', '==', true)).valueChanges(),
this.afs.collection('users', ref => ref.where('roles.professional', '==', true)).valueChanges()
])
.map((data: any) => {
console.log(data)
return data;
});
}
However, upon calling the method like this:
this.userSrv.getUsers()
.subscribe((res) => {
console.log(res);
});
I encountered an issue where it didn't execute as expected. Here are my imports:
import {Observable} from 'rxjs/Rx';
import { forkJoin } from 'rxjs/observable/forkJoin';
import 'rxjs/add/operator/map';
If you have alternative solutions or suggestions on how to tackle this problem, your guidance would be greatly appreciated. Thank you.