Angular Firestore 加入 Collections 不工作

Angular Firestore Join Collections not working

我有两个 collections 想加入。查看评论和用户。

这是我服务中的代码:

 getAll(reviewID) {
    const allComments = this.af.collection<Review>(`reviews/${reviewID}/comments`, ref => ref.orderBy('dateCreated', 'desc'))
      .valueChanges()
      .pipe(
        switchMap(reviews => {
          const res = reviews.map((review: review) => {
            return this.af.collection<User>('users', ref => ref.where('userID', '==', review.userID))
            .valueChanges()
            .pipe(
              map(user => Object.assign(review, { user }))
            );
          });
          return combineLatest(...res);
        })
      );
      return allComments;
  }

这是我的组件:

this.commentService.getAll(reviewID).subscribe(results => {
        this.comments = results;
        this.logger.log(this.comments);
      });

这主要是工作,但似乎 return 用户数组每隔一个评论。

例如:

0:
comment: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse id quam ut lacus tempor aliquam. Curabitur efficitur, lorem sit amet sodales finibus, erat arcu imperdiet dolor, eget ultricies arcu felis sit amet enim. Interdum et malesuada fames ac ante ipsum primis in faucibus."
dateCreated: Timestamp {seconds: 1549654515, nanoseconds: 0}
userID: "c8Y3q9Mn0sdfGFDgMWqh4GqJC5B2"
user: Array(0)
1:
comment: "this is the third comment"
dateCreated: Timestamp {seconds: 1549638673, nanoseconds: 0}
userID: "KEPBML9xlDfgedGZAslzOfOfbSwh2"
user: Array(1)
0: {avatar: "img.jpg", fullname: "Michael Jones", userID: "KEPBML9xlDfgedGZAslzOfOfbSwh2", username: "michaelj"}
2:
comment: "this is the second comment"
dateCreated: Timestamp {seconds: 1549562400, nanoseconds: 0}
userID: "NbPyKuTIB5dfGDGdVNmEB1h5YG2"
user: Array(0)
3:
comment: "this is the first comment"
dateCreated: Timestamp {seconds: 1549558800, nanoseconds: 0}
userID: "N2FhiRSJcdfGEDRgrCvPZa98bU4Im2"
user: Array(1)
0: {avatar: "img.jp", fullname: "Emily Jones", userID: "N2FhiRSJcdfGEDRgrCvPZa98bU4Im2", username: "emilyj"}

我已确认正在传递所有用户 ID。

我是不是做错了什么? 我不确定我缺少什么,我们将不胜感激。

我终于明白了。不知道我之前没有想到什么。

为了解决这个问题,我更改了:

this.af.collection<User>('users', ref => ref.where('userID', '==', review.userID))

this.af.doc<User>(用户/${review.userID})