I am facing the challenge of extracting data from a subcollection within my database structure. Within my main collection products
, there are documents that have a nested subcollection called reviews
.
products/prodID/reviews/reviewID
Here is my interface setup:
interface IReview {
author: string;
text: string;
rating: number;
}
export interface IProduct {
id: string;
name: string;
reviews: IReview[]
}
Function used to fetch data from the database
getProductsFromDB(): Observable<IProduct[]>{
return this.db.collection('products').snapshotChanges()
.pipe(
map(actions => {
return actions.map(a => {
let data = a.payload.doc.data() as IProduct;
data.id = a.payload.doc.id;
return data;
});
})
);
}
The issue I'm encountering is that the current function only retrieves data from the main products
collection, whereas I actually require the subcollection data to be included in the output as well.