I'm currently facing an issue with my Firebase database data structure where I have a reference to a user id. Here's an example of the original data in my collection:
{
city: new york,
country: usa
addedBy: feibf78UYV3e43 // This is the USER ID from the User Collection.
}
What I need to achieve is to fetch the user information for each document in my collection, however, the user data is being retrieved as Observable. How can I accomplish this task? The desired object structure should look like this:
{
city: new york,
country: usa
addedBy: feibf78UYV3e43 // This is the USER ID from the User Collection.
addedByProfile: {
firstName: John,
lastName: Doe,
age: 34
}
}
I attempted creating two subscriptions but encountered issues with it.
Below is a snippet of my basic code without the secondary query:
getAllIncome() {
return this.incomeService.getAllIncomeShops().subscribe(
snaps => {
const incomeShops = snaps.map(snap => {
// The call to the UserService was intended here to retrieve the user information using the getUser() method by passing the UID. However, subscribing to it caused conflicts.
return {
id: snap.payload.doc.id,
...snap.payload.doc.data()
} as IncomeShop;
});
this.showLoader = false;
this.dataSource = new MatTableDataSource(incomeShops);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
}
);
}