I need help figuring out how to merge data from two different collections in Firestore based on the `uid`. One collection is for reviews, each of which includes a unique `uid`. I want to match this `uid` with users' details such as `username` and `photoURL`.
function getUsersReviews(userId){
const reviewsRef = this.afs.collection('users-reviews', ref => ref.where('uid', '==', userId) );
reviewsRef.switchMap(reviews => {
let userObservables = reviews.map(status => this.afs.doc(`users/${userId}`))
return Observable.combineLatest(...userObservables)
.map((...users) => {
reviews.forEach((review, index) => {
review.username = users[0][index].username;
review.avatar = users[0][index].photoURL;
});
return reviews;
});
});
}
I'm having trouble getting this code to work properly. I keep encountering errors like 'switchMap' not existing on Firestore collection.
error TS2339: Property 'switchMap' does not exist on type 'AngularFirestoreCollection<{}>'.
Even though switchMap is imported, it still doesn't seem to be recognized.