【发布时间】:2017-12-27 21:10:57
【问题描述】:
我尝试根据第一次调用时收到的密钥检索subcollection 中的数据。
基本上,我想要一个我所有用户的列表,每个用户都有一个子集合。
我能够从第一个 Payload 中检索数据,但不能从下面的 pointRef 检索数据
实现这一目标的正确方法是什么?
getCurrentLeaderboard() {
return this.afs.collection('users').snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data()
const id = a.payload.doc.id;
const pointRef: Observable<any> = this.afs.collection('users').doc(`${id}`).collection('game').valueChanges()
const points = pointRef.map(arr => {
const sumPoint = arr.map(v => v.value)
return sumPoint.length ? sumPoint.reduce((total, val) => total + val) : ''
})
return { id, first_name: data.first_name, point:points };
})
})
}
【问题讨论】:
标签: angularfire2 google-cloud-firestore