I am developing a simple package that synchronizes the ElasticSearch server against MongoDB.
This package accepts an array of collections for MongoDB, each with a collection name and pipeline.
For example, the following code snippet starts synchronization by specifying MongoDb URI and name, collections array, and ElasticSearch options as they are from the ElasticSearch client package:
const mongoDbOptions: MongoDbOptions = {
uri: config.mongodbURI,
dbName: config.dbName,
collections: [
{
name: 'collection-name',
pipeline: [{ $match: { name: { $regex: 'jan' } } }, { $group: { _id: '$name', totalDocs: { $sum: 1 } } }],
},
],
};
const elasticOptions: ElasticOptions = {
node: 'http://localhost:9200',
auth: {
username: 'elastic',
password: 'elastic-user-password',
},
// tls: {
// ca: fs.readFileSync('./http_ca.crt'),
// rejectUnauthorized: false,
// },
};
const syncDbWithElasticsearch = new SyncMongoDbWithElasticSearch(mongoDbOptions, elasticOptions);
syncDbWithElasticsearch.start();
The package is available for download and usage via npm and can be found in this link.