I'm trying to restructure a database and having wicked trouble trying to populate a table with the data from it after doing so.
Here is the new structure of my database.
So, we can see newLayout > User ID > reviews, which is an array of maps. I can get as far as logging out a whole review array - but cant figure out how to access or even log out each individual object/map within a review array.
this.firebaseService.getNewReports().subscribe(docs => {
this.reports = docs.map(item => {
return {
id: item.payload.doc.id,
...item.payload.doc.data()
};
});
this.reports.forEach(element => {
console.log(element.reviews);
});
});
Each review array being logged out
I cant even log out one single object - I assumed even console.log(element.reviews[0]) would work, but it says "cannot read property 0 of undefined". I can only get as far as logging out the whole reviews array.
What I'm looking for is to iterate and retrieve the contents of every review from each document at once and assign them into one big array of objects to use as a source for a MatTableDataSource.
Like so
[
{county: Cork, dateAdded: " ", ...},
{county: Cork, dateAdded: " ", ...},
{county: Clare, dateAdded: " ", ...}
]
This was an easy operation in my previous simple database structure as I could just retrieve the entire collection and assign it to an array. The structure was impractical for other features so now I'm including meaningful ID's.
Any help would be greatly appreciated, the amount of time this has taken is getting very silly. I've trawled the internet and documents for solutions, but I'm starting to feel I'm just doing it wrong from the start with my database structure.