使用多个ID查询Firebase AngularFirestoreCollection

时间:2018-10-24 15:00:29

标签: angular firebase google-cloud-firestore observable

我要传递一个省ID provinceIds数组,我想查询并返回每个Universities中的所有Province。到目前为止,我只从第一省返回大学。总共可以传递9个可能的ID(南非9个省)。我尝试进行迭代,最后以很多奇怪的代码结尾,“我不理解自己。”

如果您知道执行此操作的任何其他方法,我会开放的。

enter image description here

export class UniversitiesService {
  private collection: AngularFirestoreCollection<University>;
  universities: Observable<University[]>;
  constructor(
    private afs: AngularFirestore
  ) { }

  getUniversitiesByProvince(provinceIds: string[]): Observable<University[]> {
    this.collection = this.afs.collection('Universities',
        ref => ref.where('provinceID', '==', provinceIds[0]));
    this.universities = this.collection.snapshotChanges()
      .map(actions => {
        return actions.map(a => {
          const data = a.payload.doc.data() as University;
          data.Id = a.payload.doc.id;
          return data;
        });
      });
    return this.universities;
  }

}

0 个答案:

没有答案