在节点中使用 mongodb,我们可以使用异步迭代器。基本示例:
const documents: Record<string, any>[] = [];
let cursor = db.collection('randomcollection').find();
for await (let doc of cursor) {
documents.push(document);
}
异步迭代器如何使用 fp-ts 转换为函数式编程?上面的for循环可以用fp-ts表达吗?我已经搜索过,但没有找到有关异步迭代器的文档。
const whereIamRightNow = pipe(
TE.bindTo('db')(createMongoClientWithEncryption),
TE.bind('cursor', ({ db }) => TE.of(getQueryCursor(dateRange)(db.client))),
// how to async iterate over query cursor and call a processing function for each record?
);