Rxjs 如何在一个承诺中加载firebase集合及其所有子集合?

Rxjs 如何在一个承诺中加载firebase集合及其所有子集合?,rxjs,angularfire2,angularfire,rxjs-observables,rxjs-pipeable-operators,Rxjs,Angularfire2,Angularfire,Rxjs Observables,Rxjs Pipeable Operators,我目前正试图弄清楚如何使用RxJS加载angular/fire集合,包括它的所有子集合 这是我目前的做法: return this.collectionRef.valueChanges().pipe( flatMap((entities: Entity[]) => entity), mergeMap((entity: Entity) => this.setSubCollection1(entity)), mergeMap((entity: Enti

我目前正试图弄清楚如何使用RxJS加载angular/fire集合,包括它的所有子集合

这是我目前的做法:

return this.collectionRef.valueChanges().pipe(
      flatMap((entities: Entity[]) => entity),
      mergeMap((entity: Entity) => this.setSubCollection1(entity)),
      mergeMap((entity: Entity) => this.setSubCollection2(entity)),
      scan((entities: Entity[], entity: Entity) => entities.filter(a => a.id !== entity.id).concat(entity), [])
    );
并将文档加载到其子集合中

  private setSubCollection1 = (entity: Entity): Observable<Entity> => {
    return this.subCollectionRef.valueChanges(actor).pipe(
      map((subEntities1: SubEntity1[]) => {
        entity.subEntities1 = subEntities1;
        return entity;
      })
    );
  }
private setSubCollection1=(实体:实体):可观察=>{
返回此.subCollectionRef.valueChanges(actor.pipe)(
映射((子实体1:子实体1[])=>{
entity.subEntities1=子实体1;
返回实体;
})
);
}
当流量满时,它工作正常。 但是现在我想在一个单一的承诺中获取所有数据:我已经尝试了
.first().toPromise()
,但是这只获取第一个条目,如果集合没有条目,则不会完成。在查询中使用
reduce
也不起作用,因为
valueChanges()
永远不会结束

我是否使用了错误的运算符?或者关于如何解决这个问题的其他想法

我希望收到你的来信