代码之家  ›  专栏  ›  技术社区  ›  Teoman shipahi

Firebase startAfter不为doc ref工作

  •  1
  • Teoman shipahi  · 技术社区  · 8 年前

    以下是我的观点: https://firebase.google.com/docs/firestore/query-data/query-cursors

    我有如下代码;

    async List(query: any): Promise<Array<any>> {
        let collectionQuery = super.GetCollectionReference();
        if (query.VideoChannelId) {
          collectionQuery = collectionQuery.where(
            "VideoChannel.Id",
            "==",
            query.VideoChannelId
          );
        }
        let startAfterDoc: any = "";
        if (query.StartAfter) {
          startAfterDoc = await super.GetDocumentReference(query.StartAfter);
        }
        collectionQuery = collectionQuery
          .orderBy(query.OrderBy, "desc")
          .startAfter(startAfterDoc)
          .limit(query.Limit);
        let items = await super.List(collectionQuery);
        return items;
      }
    

    和实用方法:

     GetDocumentReference(id: string): any {
        return this.GetCollectionReference().doc(id);
      }
      async GetDocumentSnapshot(id: string): Promise<any> {
        return await this.GetDocumentReference(id).get();
      }
      GetCollectionReference(): any {
        return this.db.collection(this.CollectionName);
      }
    

    不管我传递给查询的值是什么。开始之后,它总是返回集合中的顶级文档。 我很确定文档中存在id查询。开始之后。

    如果我使用 GetDocumentSnapshot 而不是 GetCollectionReference 那我就要 parse error at firebase API .

    索引已添加到 query.OrderBy (CreateDate)和Id字段。

    我可能会错过什么?

    0 回复  |  直到 8 年前
    推荐文章