Firebase startAfter对文档引用不起作用

时间:2018-07-22 17:55:22

标签: node.js firebase google-cloud-firestore google-cloud-functions

我关注的文档: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);
  }

无论我传递的查询值是什么,StartAfter总是返回集合中的顶级文档。  我很确定文档存在ID查询。StartAfter。

如果我使用GetDocumentSnapshot而不是GetCollectionReference,那么我会得到parse error at firebase API

已为query.OrderBy(创建日期)和ID字段添加了索引。

在这里我可能会想念什么?

0 个答案:

没有答案
相关问题