0.51.0 • Published 3 months ago

mongo2elastic v0.51.0

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

Mongo to Elastic

Sync MongoDB to Elasticsearch

import { initSync, crate } from 'mongo2crate'
import { default as Redis } from 'ioredis'
import { MongoClient } from 'mongodb'
import retry from 'p-retry'
import elasticsearch from '@elastic/elasticsearch'

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

const elastic = new elasticsearch.Client()

const sync = initSync(new Redis(), db.collection('myCollection'), elastic, {
  omit: ['password', 'unneededStuff'],
})
// Log events
sync.emitter.on('process', console.info)
sync.emitter.on('error', console.error)
sync.emitter.on('cursorError', () => process.exit(1))
// Create index with ignore_malformed enabled
await sync.createIndexIgnoreMalformed().catch(console.warn)
// Create mapping
const schema = await sync.getCollectionSchema(db)
if (schema) {
  await sync.createMappingFromSchema(schema)
}
// Process change stream events
const changeStream = await sync.processChangeStream()
changeStream.start()
// Detect schema changes and stop change stream if detected
const schemaChange = await sync.detectSchemaChange(db)
schemaChange.start()
sync.emitter.on('schemaChange', changeStream.stop)
// 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 to the appropriate values:

MONGO_CONN="mongodb+srv://..."
ELASTIC_NODE='https://elastic-node-url-here.com'
ELASTIC_USERNAME="username-here"
ELASTIC_PASSWORD="password-here"

Then run npm test to run the tests.

0.51.0

3 months ago

0.50.0

5 months ago

0.49.0

8 months ago

0.48.0

8 months ago

0.46.0

9 months ago

0.47.0

8 months ago

0.43.0

11 months ago

0.44.0

11 months ago

0.42.0

11 months ago

0.45.0

10 months ago

0.41.0

2 years ago

0.38.0

2 years ago

0.40.0

2 years ago

0.39.1

2 years ago

0.39.0

2 years ago

0.37.0

2 years ago

0.36.0

2 years ago

0.35.0

2 years ago

0.34.0

2 years ago

0.33.1

2 years ago

0.33.0

2 years ago

0.32.0

2 years ago

0.21.0

2 years ago

0.20.0

2 years ago

0.31.0

2 years ago

0.30.0

2 years ago

0.29.0

2 years ago

0.28.0

2 years ago

0.27.0

2 years ago

0.26.0

2 years ago

0.25.0

2 years ago

0.24.1

2 years ago

0.24.0

2 years ago

0.23.0

2 years ago

0.22.0

2 years ago

0.19.0

2 years ago

0.13.0

3 years ago

0.14.0

3 years ago

0.15.0

3 years ago

0.14.1

3 years ago

0.16.0

3 years ago

0.17.0

3 years ago

0.18.0

2 years ago

0.17.1

3 years ago

0.10.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.11.0

3 years ago

0.9.0

3 years ago

0.8.1

3 years ago

0.12.0

3 years ago

0.8.0

3 years ago

0.8.2

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.1.0

3 years ago