Reputation: 24472
I stored in my database a list of IDS of posts the user has liked, now I want to show the list of posts he liked.
I'm trying to map the IDS to the posts using RXJS.
So far, I got the list of the ids in a snapshot, and i'm not sure how to switch them to the documents themselves:
myLikedConfessions() {
return this.db.doc(this.USER_COLLECTION)
.collection('likedConfs',
ref => ref.limit(5))
.snapshotChanges()
.mergeMap((ids) => {
console.log(ids);
// each id should have the observable result of: this.db.collection('posts').doc(docID);
return Observable.of({});
})
}
Any idea?
Upvotes: 1
Views: 262
Reputation: 96891
Just use forkJoin
that waits until all source Observables complete:
...
.mergeMap((ids) => {
const observables = ids.map(id => this.db.collection('posts').doc(id))
return Observable.forkJoin(observables)
})
Upvotes: 2