如何查询Firebase数据库以从ID数组返回angularfirelist

时间:2019-06-14 16:26:09

标签: angular typescript ionic-framework angularfire2 ionic4

我有一个对象,该对象的属性为ID列表。

const obj = { list: ['id-1', 'id-2', 'id-3'] };

当前,这就是我所能做的。但是它返回一个Observables数组。

// Class variable...
records: Observable<Record>[];

constructor(private afDB: AngularFireDatabase) {}

getRecords () {
  this.records = obj.list.map(id => this.afDB.object(`path/to/collection/${id}`));
}

this.records数组不同,将Observable作为Observable的数组似乎不是最适合在模板中使用的。

我宁愿拥有records: Observable<Record[]>而不是records: Observable<Record>[]

反正是否有将这些ID作为查询函数的一部分传递给angularfire数据库的原因?

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

afDB.collection('yourCollection', ref => ref.where('id', '==', 'yourId'));

https://github.com/angular/angularfire2/blob/master/docs/firestore/querying-collections.md上找到了这个