@360-l/mongo-bulk-data-migration
Version:
MongoDB bulk data migration for node scripts
52 lines (51 loc) • 1.85 kB
TypeScript
import type { LoggerInterface } from '../types';
import type { ObjectId, Collection, UnorderedBulkOperation, Document, WriteConcernError, WriteError } from 'mongodb';
export declare const INITIAL_BULK_INFOS: {
insertedIds: any[];
nInserted: number;
nMatched: number;
nModified: number;
nRemoved: number;
nUpserted: number;
ok: number;
upserted: any[];
writeConcernErrors: any[];
writeErrors: any[];
};
export interface BulkOperationResult {
insertedIds: ObjectId[];
nInserted: number;
nMatched: number;
nModified: number;
nRemoved: number;
nUpserted: number;
ok: number;
upserted: ObjectId[];
writeConcernErrors: WriteConcernError[];
writeErrors: WriteError[];
}
export declare const NO_COUNT_AVAILABLE = -1;
export declare abstract class AbstractBulkOperationResults<TSchema extends Document> {
protected readonly collection: Collection<TSchema>;
protected readonly results: BulkOperationResult;
protected bulk: UnorderedBulkOperation;
protected totalBulkOps: number;
protected readonly totalOperations: number | typeof NO_COUNT_AVAILABLE;
protected readonly logger: LoggerInterface;
constructor(collection: Collection<TSchema>, logger: LoggerInterface, totalOperations: number);
abstract logExecutionStatus(executionResults: BulkOperationResult): this;
get size(): number;
get progress(): number;
get totalOperationsDone(): number;
private initialize;
execute(continueOnBulkWriteError?: boolean): Promise<this>;
private mergeResults;
getResults(): BulkOperationResult;
protected buildLogObject(executionResults: BulkOperationResult): {
progress: {
totalOperationsDone: number;
estimatedTotalOperations: string | number;
percent: string;
};
};
}