mongo2mongo
Version:
Sync one MongoDB collection to another MongoDB collection
66 lines (65 loc) • 2.91 kB
TypeScript
import type { Redis } from 'ioredis';
import * as mongoChangeStream from 'mongochangestream';
import { type ChangeStreamOptions, type ScanOptions } from 'mongochangestream';
import type { Collection } from 'mongodb';
import type { QueueOptions } from 'prom-utils';
import type { SyncOptions } from './types.js';
export declare const initSync: (redis: Redis, source: Collection, destination: Collection, options?: SyncOptions & mongoChangeStream.SyncOptions) => {
/**
* Process MongoDB change stream for the given collection.
* `options.batchSize` defaults to 500.
* `options.timeout` defaults to 30 seconds.
*/
processChangeStream: (options?: QueueOptions & ChangeStreamOptions) => Promise<{
start: () => Promise<void>;
stop: () => Promise<void>;
restart: () => Promise<void>;
state: Pick<{
get: () => mongoChangeStream.State;
change: (newState: mongoChangeStream.State) => void;
waitForChange: (...newStates: mongoChangeStream.State[]) => Promise<void>;
is: (...states: mongoChangeStream.State[]) => boolean;
canChange: (newState: mongoChangeStream.State) => boolean;
maybeChange: (newState: mongoChangeStream.State) => boolean;
getElapsedTime: () => number;
}, "get" | "is">;
}>;
/**
* Run initial collection scan. `options.batchSize` defaults to 500.
* Sorting defaults to `_id`.
*/
runInitialScan: (options?: QueueOptions & ScanOptions) => Promise<{
start: () => Promise<void>;
stop: () => Promise<void>;
restart: () => Promise<void>;
state: Pick<{
get: () => mongoChangeStream.State;
change: (newState: mongoChangeStream.State) => void;
waitForChange: (...newStates: mongoChangeStream.State[]) => Promise<void>;
is: (...states: mongoChangeStream.State[]) => boolean;
canChange: (newState: mongoChangeStream.State) => boolean;
maybeChange: (newState: mongoChangeStream.State) => boolean;
getElapsedTime: () => number;
}, "get" | "is">;
}>;
emitter: import("eventemitter3").EventEmitter<"process" | mongoChangeStream.Events, any>;
reset: () => Promise<void>;
getCollectionSchema: (db: import("mongodb").Db) => Promise<mongoChangeStream.JSONSchema>;
detectSchemaChange: (db: import("mongodb").Db, options?: mongoChangeStream.ChangeOptions) => Promise<{
start: () => void;
stop: () => void;
}>;
detectResync: (resyncCheckInterval?: number) => {
start: () => void;
stop: () => void;
};
keys: {
scanCompletedKey: string;
lastScanIdKey: string;
changeStreamTokenKey: string;
schemaKey: string;
lastChangeProcessedAtKey: string;
lastScanProcessedAtKey: string;
resyncKey: string;
};
};