My data in firebase looks like below:
/users
--key1
--cards
--card1
--name: X
--age: 40
--card2
--name Y
--age 45
--email: [email protected]
the code to query data looks like below
this.userCardList = this.db.list<Card>('users', ref => ref.orderByChild('email').equalTo(email))
return this.userCardList.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ key: c.payload.key, ...c.payload.val()}))
)
) ;
i am invoking in my component.ts as below
ngOnInit() {
this.cards = this.dataSvc.fetchUserCards(this.core.email).pipe(
map((cards: any) => cards.map(cardObj => {
var c = new Card(cardObj.key)
c.firstName = cardObj._firstName
c.lastName = cardObj._lastName
c.jobTitle = cardObj._jobTitle
return c
}))
);
}
The problem is that the above code is not mapped to cards node rather key1 node. if replace it as users/cards that does not work either.
My expectation is to be able to get cards node data rather the parent node.
card1andcard2contain...I want the cards node. So how should it look like? Do you meancards = [{card1: {...}}, {card2: {...}}]?