mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
// Loaded from https://deno.land/x/mongo@v0.20.0/src/collection/commands/aggregate.ts
|
|
|
|
|
|
import { CommandCursor } from "../../protocol/cursor.ts";
|
|
import { WireProtocol } from "../../protocol/protocol.ts";
|
|
import { AggregateOptions, Document } from "../../types.ts";
|
|
|
|
interface AggregateCursorContext {
|
|
dbName: string;
|
|
collectionName: string;
|
|
protocol: WireProtocol;
|
|
pipeline: Document;
|
|
options?: AggregateOptions;
|
|
}
|
|
|
|
export class AggregateCursor<T> extends CommandCursor<T> {
|
|
#context: AggregateCursorContext;
|
|
|
|
private async executor() {
|
|
const { dbName, pipeline, collectionName, protocol, options } =
|
|
this.#context;
|
|
|
|
const { cursor } = await protocol.commandSingle(dbName, {
|
|
aggregate: collectionName,
|
|
pipeline,
|
|
cursor: {
|
|
batchSize: options?.batchSize || 1000,
|
|
},
|
|
...options,
|
|
});
|
|
return {
|
|
...cursor,
|
|
id: cursor.id.toString(),
|
|
};
|
|
}
|
|
|
|
constructor(context: AggregateCursorContext) {
|
|
super(context.protocol, () => this.executor());
|
|
this.#context = context;
|
|
}
|
|
}
|