Registry / database / mongo2mongo

mongo2mongo

JSON →
library0.40.0jsnpmunverified

Sync one MongoDB collection to another MongoDB collection, supporting change streams and initial scans. Current stable version is 0.40.0, with regular releases. Requires Node >=16, peer dependencies include ioredis and mongodb (>=6.8.0). Key differentiators: built-in support for field omission, event-driven progress tracking, and batched initial sync with configurable batch sizes. Ships TypeScript types.

npm install mongo2mongo
INSTALL
IMPORT
SIG · MONGO2MONGO
M
mongo2mongo
databasejavascriptv0.40.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

initSync
import { initSync } from 'mongo2mongo'
const initSync = require('mongo2mongo')
ESM-only; CommonJS require is not supported.
Sync
import type { Sync } from 'mongo2mongo'
import { Sync } from 'mongo2mongo'
Sync is a TypeScript type, not a runtime export.
SyncOptions
import type { SyncOptions } from 'mongo2mongo'
import { SyncOptions } from 'mongo2mongo'
SyncOptions is a TypeScript type for configuration.

Initialize sync between two MongoDB collections with Redis, listen to events, start change stream and initial scan.

import { initSync } from 'mongo2mongo'; import Redis from 'ioredis'; import { MongoClient } from 'mongodb'; const client = await MongoClient.connect(process.env.MONGO_URI ?? ''); const db = client.db(); const sync = initSync( new Redis(process.env.REDIS_URL ?? ''), db.collection('source'), db.collection('destination'), { omit: ['password'] } ); sync.emitter.on('process', console.info); sync.emitter.on('error', console.error); const changeStream = await sync.processChangeStream(); changeStream.start(); const initialScan = await sync.runInitialScan({ batchSize: 1000 }); initialScan.start();
Debug
Known issues
breakingVersion 0.40.0 requires mongodb >=6.8.0 and ioredis >=5.4.1; older driver versions cause runtime errors.
fix
Update mongodb to >=6.8.0 and ioredis to >=5.4.1.
affects: >=0.40.0
breakingNode.js version must be >=16.0.0; older versions are not supported.
fix
Upgrade Node.js to 16 or later.
affects: >=0.40.0
gotchaThe sync object's emitter property must be accessed before calling processChangeStream or runInitialScan to avoid missing events.
fix
Attach event listeners immediately after initSync.
affects: >=0.0.0
deprecatedThe 'omit' option accepts an array of field names to exclude from sync; this may be deprecated in future versions.
fix
Check future releases for alternative API.
affects: >=0.30.0
gotchaIf source and destination databases are different, ensure both connections are provided correctly via MongoClient.
fix
Use separate MongoClient instances if needed, or connect to the same client with different databases.
affects: >=0.0.0
breakingThe package previously exported a default export; now only named export { initSync } is available.
fix
Change import to named import: import { initSync } from 'mongo2mongo'.
affects: >=0.40.0
Errors
Common errors & fixes
Cannot find module 'mongo2mongo'
Package not installed or ESM module resolution issue.
fix
Run npm install mongo2mongo or ensure package.json has 'type': 'module'.
initSync is not a function
Using default import or incorrect require syntax.
fix
Use named import: import { initSync } from 'mongo2mongo'.
The module 'ioredis' is not compatible with the 'mongodb' driver version
Peer dependency version mismatch.
fix
Install compatible versions: npm install ioredis@5.4.1 mongodb@6.8.0
TypeError: Cannot read properties of undefined (reading 'on')
Attempting to use sync.emitter before it's initialized or without calling initSync.
fix
Ensure you call initSync and use the returned sync object.
Upgrade
Version history
0.40.0latest on npm
Audit
Dependencies
ioredisrequiredUsed for managing change stream cursors and coordination
mongodbrequiredOfficial MongoDB driver for interacting with databases
Agent activity
10 hits · last 30 days
node
8
Resources
mongo2mongo — npm install mongo2mongo · libregistry