【问题标题】:RxJS & Firestore - map list of document ids to the documentsRxJS 和 Firestore - 将文档 ID 列表映射到文档
【发布时间】:2018-08-24 08:58:23
【问题描述】:

我在我的数据库中存储了用户喜欢的帖子的 IDS 列表,现在我想显示他喜欢的帖子列表。

我正在尝试使用 RXJS 将 IDS 映射到帖子。

到目前为止,我在快照中获得了 id 列表,但我不确定如何将它们切换到文档本身:

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({});
      })
  }

有什么想法吗?

【问题讨论】:

    标签: angular rxjs google-cloud-firestore angularfire2


    【解决方案1】:

    只需使用 forkJoin 等待所有源 Observable 完成:

    ...
    .mergeMap((ids) => {
      const observables = ids.map(id => this.db.collection('posts').doc(id))
      return Observable.forkJoin(observables)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 2021-09-03
      • 1970-01-01
      • 2018-06-25
      • 2023-03-05
      • 2020-07-24
      • 2018-03-19
      相关资源
      最近更新 更多