本文整理汇总了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;未经允许,请勿转载。 |
请发表评论