I need to get data from a subcollection.
I have a collection products
, it contains documents with a subcollection reviews
.
products/prodID/reviews/reviewsID
My interfaces:
interface IReview {
author: string;
text: string;
rating: number;
}
export interface IProduct {
id: string;
name: string;
review:IReview[]
}
Function for retrieve data from db
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 problem is that now this function returns only the products
collection data. But I need the subcollection data to be returned too.