【问题标题】:How to get data from `where` query in firebase如何从 Firebase 中的“where”查询中获取数据
【发布时间】:2018-11-17 17:36:53
【问题描述】:

我不确定如何处理为 this.actions 返回的查询对象

this.actionCollection = this.db.collection('actions');
this.actions = this.actionCollection.ref.where('filterId', '==', this.filterId)

我应该如何处理this.actions?我尝试将其设置为我的视图,但出现此错误Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'

<h4>Actions List</h4>
<ul>
  <li *ngFor="let action of actions | async">
    {{action | json}}
  </li>
</ul>

【问题讨论】:

    标签: angular firebase google-cloud-firestore


    【解决方案1】:

    您需要对其调用 get 方法。这将返回 firebase.firestore.QuerySnapshot 类型的值。

    它本质上是一个Promise,因此您可以将then 方法链接到它以获取解析的数据。来,试试这个:

    this.actions = this.actionCollection.ref
      .where('filterId', '==', this.filterId)
      .get()
      .then(querySnapshot => {
        querySnapshot.forEach(doc => {
            console.log(doc.id, " => ", doc.data());
        });
      });
    

    请查看 Get multiple documents from a collection 以获得参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 2018-12-06
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      相关资源
      最近更新 更多