You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{initSync,crate}from'mongo2crate'import{defaultasRedis}from'ioredis'import{MongoClient}from'mongodb'importretryfrom'p-retry'importelasticsearchfrom'@elastic/elasticsearch'constclient=awaitMongoClient.connect()constdb=client.db()constelastic=newelasticsearch.Client()constsync=initSync(newRedis(),db.collection('myCollection'),elastic,{omit: ['password','unneededStuff'],})// Log eventssync.emitter.on('process',console.info)sync.emitter.on('error',console.error)sync.emitter.on('cursorError',()=>process.exit(1))// Create index with ignore_malformed enabledawaitsync.createIndexIgnoreMalformed().catch(console.warn)// Create mappingconstschema=awaitsync.getCollectionSchema(db)if(schema){awaitsync.createMappingFromSchema(schema)}// Process change stream eventsconstchangeStream=awaitsync.processChangeStream()changeStream.start()// Detect schema changes and stop change stream if detectedconstschemaChange=awaitsync.detectSchemaChange(db)schemaChange.start()sync.emitter.on('schemaChange',changeStream.stop)// Run initial scan of collection batching documents by 1000constoptions={batchSize: 1000}constinitialScan=awaitsync.runInitialScan(options)initialScan.start()