I'm trying to figure out a way to get a collection of documents along with their subcollection data.
For example, my tree is...
-locations
-{locationId}
-historic
-april
-airTemp: 12.4
-displayOrder: 4
-august
-airTemp: 14.5
-displayOrder: 9
-december
-airTemp: 13.5
-displayOrder: 12
etc..
...where locationId is a document and historic is the subcollection with monthly documents in it.
I know how to get the top level collection items and store it into an array but I want to add their subcollection data (i.e. the jan, feb, etc.) into each document as well.
var locations = []
let ref = db.collection('locations')
db.collection('locations').get()
.then(snapshot => {
snapshot.forEach(doc => {
let location = doc.data()
location.id = doc.id
location.name = doc.name
// get the historic subcollection data here
})
})
How can I get the combined data (collection and subcollection) from each object and then push it into an array?
bounty is wrong structure each month should be its own object