Reputation: 167
I'm trying to reach the data when theres a collection, and inside that collection a doc and inside that doc a collection again.
But im not able to do it.
getTeams() {
this.db
.doc('epicseven')
.collection('teams')
.snapshotChanges()
.subscribe(data => {
console.log(data);
});
}
this is the database.
I want to access the JSON with the last array, so i can iterate in the html.
Thanks for your help.
Upvotes: 0
Views: 44
Reputation: 482
use this.
getTeams() {
this.db
.collection('epicseven')
.doc('teams')
.collection([TEAM_NAME])
.doc([ID])
.snapshotChanges()
.pipe(map(list => list.map(item => {
let data = item.payload.doc.data();
let id = item.payload.doc.id;
return { id, ...data }
}))).subscribe(res => {
console.log(res);
});
}
Upvotes: 0
Reputation: 468
I think you mistaken collection for doc in the beginning. 'epicseven' is a collection. After a collection is always a doc and inside a doc there's either a reference to a collection or values itself. Beside you didn't go down deep enough to get the desired data, my guess is you query would only get the name of the team collection since Firestore query is shallow by default. I would suggest the following query:
getTeams() {
this.db
.collection('epicseven')
.doc('teams')
.collection([TEAM_NAME])
.doc([ID])
.valueChanges()
.subscribe(data => {
console.log(data);
});
}
Upvotes: 1