在Firestore中读取root,然后读取多个子集合

时间:2018-07-30 15:55:36

标签: angular angular5 google-cloud-firestore angularfire2

我在Firestore中有两个集合A和B,我正在使用Angular 5.2和Angularfire2。 A是根集合,A中的每个文档都有一个子集合B。

我面临以下挑战:

  1. 我需要从集合A中读取一个子集
  2. 对于子集中的每个文档,都需要读取基础子集合。
  3. 数据将显示在表格中。 读取子集将需要使用.snapshot(),因为我需要该子集的ID。然后,我想遍历结果并读取每个基础子集合。

我尝试使用switchMap,concatMap,concatAll等,但是对于每种类型,我都会得到不同的输入错误。

const rootCollection = this.afs
  .doc(collection.USERS + `/${email}`)
  .collection<MyMeasurement>(collection.MY_MEASUREMENT, ref =>
    ref.where('selected', '==', true).orderBy('name', 'asc')
  )
  .snapshotChanges()
  .pipe(
    map(changes => {
      return changes.map(action => {
        const data = action.payload.doc.data() as MyMeasurement;
        data.id = action.payload.doc.id;
        return data;
      });
    })
  );

const concatCollection = rootCollection.pipe(concatMap(data => data.forEach(element => {      
  // her comes the inner observer 
  // Her is the error message:
  // Argument of type '(data: MyMeasurement[]) => void' is not assignable to parameter of type '(value: MyMeasurement[], index: number) => ObservableInput<{}>'.
  //Type 'void' is not assignable to type 'ObservableInput<{}>'.
})))

const subscribe.concatCollection(data => console.log(data));

0 个答案:

没有答案