Firestore动态查询返回所有文档

时间:2019-11-19 22:13:42

标签: firebase google-cloud-firestore

我一直在到处寻找,但是我不明白为什么我的代码无法正常工作。我需要创建一个动态查询。我相信我的代码与online为动态查询提供的一些示例非常相似,但是由于某些原因,当我有return query语句时,我的查询将返回所有文档。如果删除该语句,则会得到正确的快照(已过滤的文档)。我已经注释了部分代码以对其进行测试。在下面您可以看到我需要为某些过滤器值提供条件,然后在每个if语句中应用一个where条件。因此,我需要大括号和一个返回查询。如果需要更清晰的代码,请让我知道,我会做得更好。请一些帮助,无法在线找到解决方案。

  private getDiscountsCollFromFt$(filter: Filter): Observable<DocumentChangeAction<unknown>[]> {
    return this.firestore.collection(Constants.fbPathRefDiscountsNode, (queryFn) => 

      // if(filter.ctg_ref){
      //   Some additional where       
      // }

      // if(filter.discountLocationTypeFilter != "0"){
      //   let isOnlineQuery: boolean = filter.discountLocationTypeFilter == "2";
      //   console.log(isOnlineQuery)
      //   console.log(queryFn)

      queryFn.where("isOnline", "==", true)
      // }

      // if(filter.extraCtg){
      //   Some additional where  
      // }

      // if(filter.searchInput){
      //   Some additional where  
      // }

      // Uncomment following line and add curly brackets after arrow symbol and return query and the query will work
      // return query;

    ).snapshotChanges();
  }

0 个答案:

没有答案
相关问题