0.34.0 • Published 11 months ago

mongo2mongo v0.34.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Mongo to Mongo

Sync one MongoDB collection to another MongoDB collection

The collections can be in the same database or different databases.

import { initSync } from 'mongo2mongo'
import { default as Redis } from 'ioredis'
import { MongoClient } from 'mongodb'
import retry from 'p-retry'

const client = await MongoClient.connect()
const db = client.db()

const sync = initSync(
  new Redis(),
  db.collection('sourceCollection'),
  db.collection('destinationCollection'),
  { omit: ['password', 'unneededStuff'] }
)
// Log events
sync.emitter.on('process', console.info)
sync.emitter.on('error', console.error)
sync.emitter.on('cursorError', () => process.exit(1))
// Process change stream events
const changeStream = await sync.processChangeStream()
changeStream.start()
// Run initial scan of collection batching documents by 1000
const options = { batchSize: 1000 }
const initialScan = await sync.runInitialScan(options)
initialScan.start()

Run the tests locally

Create a .env file with the following variables set for your MongoDB cluster(s). Note: source and destination can be the same.

MONGO_SOURCE_CONN="mongodb+srv://..."
MONGO_DESTINATION_CONN="mongodb+srv://..."

Then run npm test to run the tests.

0.34.0

11 months ago

0.33.0

12 months ago

0.32.0

1 year ago

0.31.0

1 year ago

0.30.0

1 year ago

0.29.0

1 year ago

0.28.0

1 year ago

0.27.0

2 years ago

0.26.0

2 years ago

0.21.0

3 years ago

0.25.0

3 years ago

0.24.0

3 years ago

0.23.0

3 years ago

0.22.0

3 years ago

0.21.1

3 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.12.0

3 years ago

0.13.0

3 years ago

0.14.0

3 years ago

0.15.0

3 years ago

0.16.0

3 years ago

0.15.1

3 years ago

0.17.0

3 years ago

0.18.0

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.5.2

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.1.0

3 years ago