mongo2elastic
Version:
Sync MongoDB collections to Elasticsearch
81 lines (80 loc) • 3.5 kB
TypeScript
import elasticsearch from '@elastic/elasticsearch';
import type { Redis } from 'ioredis';
import { type ChangeStreamOptions, type ScanOptions } from 'mongochangestream';
import * as mongoChangeStream from 'mongochangestream';
import type { Collection } from 'mongodb';
import type { QueueOptions } from 'prom-utils';
import type { ConvertOptions, SyncOptions } from './types.js';
export declare const initSync: (redis: Redis, collection: Collection, elastic: elasticsearch.Client, 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">;
}>;
/**
* Create index with ignore_malformed enabled for the index.
*/
createIndexIgnoreMalformed: (settings?: object) => Promise<void>;
/**
* Create mapping from MongoDB JSON schema
*/
createMappingFromSchema: (jsonSchema: object, options?: ConvertOptions) => Promise<elasticsearch.estypes.IndicesResponseBase>;
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;
};
pausable: {
pause: () => void;
resume: () => void;
maybeBlock: () => Promise<void> | undefined;
readonly isPaused: boolean;
};
};