當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mongodb.Cursor類代碼示例

本文整理匯總了TypeScript中mongodb.Cursor的典型用法代碼示例。如果您正苦於以下問題:TypeScript Cursor類的具體用法?TypeScript Cursor怎麽用?TypeScript Cursor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Cursor類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: transformNodeFunction

    public async getGraphQLConnectionFromMongoCursor<InputNode, OutputNode>(
        mongoCursor: Cursor, // return value of .find() in mongodb
        first: number = 10, // how many to fetch
        after?: string, // base64 encoded string
        transformNodeFunction?: (node: InputNode) => OutputNode,
    ) {
        // default value:
        if (!after) {
            after = this.createCursor();
        }
        // decode cursor:
        const cursor = this.decodeCursor(after);

        // get totalCount and entries for nodes
        const [totalCount, entries] = await Promise.all([
            mongoCursor.count(),
            mongoCursor
                .sort(cursor.sort)
                .skip(cursor.skip)
                .limit(first)
                .toArray(),
        ]);

        // get startCursor and endCursor
        const startCursor: string = this.createCursor({
            skip: cursor.skip,
            sort: cursor.sort,
        });

        const endCursor: string = this.createCursor({
            skip: cursor.skip + entries.length,
            sort: cursor.sort,
        });

        // return graphql connection response
        return {
            edges: entries.map((entry: InputNode, index: number) => {
                return {
                    cursor: this.createCursor({
                        skip: cursor.skip + index + 1,
                        sort: cursor.sort,
                    }),
                    node: transformNodeFunction(entry),
                };
            }),
            items: entries.map(transformNodeFunction),
            pageInfo: {
                endCursor,
                hasNextPage: cursor.skip + first <= totalCount - 1,
                startCursor,
            },
            totalCount,
        };
    }
開發者ID:vnenkpet,項目名稱:japanese,代碼行數:54,代碼來源:Pagination.ts

示例2: close

  close() {
    if (this.cursor) {
      this.cursor.close();
    }

    return Promise.resolve();
  }
開發者ID:liwijs,項目名稱:liwi,代碼行數:7,代碼來源:MongoCursor.ts

示例3: next

 next(): Promise<any> {
   return this.cursor.next().then((value) => {
     this._result = value;
     this.key = value && value._id;
     return this.key;
   });
 }
開發者ID:liwijs,項目名稱:liwi,代碼行數:7,代碼來源:MongoCursor.ts

示例4: toArray

 toArray(): Promise<Model[]> {
   return this.cursor.toArray();
 }
開發者ID:liwijs,項目名稱:liwi,代碼行數:3,代碼來源:MongoCursor.ts

示例5: count

 count(applyLimit: boolean = false) {
   return this.cursor.count(applyLimit);
 }
開發者ID:liwijs,項目名稱:liwi,代碼行數:3,代碼來源:MongoCursor.ts

示例6: limit

 limit(newLimit: number): Promise<this> {
   this.cursor.limit(newLimit);
   return Promise.resolve(this);
 }
開發者ID:liwijs,項目名稱:liwi,代碼行數:4,代碼來源:MongoCursor.ts

示例7: advance

 advance(count: number): void {
   this.cursor.skip(count);
 }
開發者ID:liwijs,項目名稱:liwi,代碼行數:3,代碼來源:MongoCursor.ts


注:本文中的mongodb.Cursor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。