{"id":13462134,"url":"https://github.com/iftech-engineering/mongo-es","last_synced_at":"2025-03-25T01:31:46.790Z","repository":{"id":42361530,"uuid":"90821728","full_name":"iftech-engineering/mongo-es","owner":"iftech-engineering","description":"A MongoDB to Elasticsearch connector","archived":false,"fork":false,"pushed_at":"2022-04-08T23:42:38.000Z","size":801,"stargazers_count":189,"open_issues_count":5,"forks_count":30,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-05-19T20:02:18.576Z","etag":null,"topics":["connector","elasticsearch","etl","mongodb"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iftech-engineering.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-10T04:44:01.000Z","updated_at":"2024-02-20T08:45:32.000Z","dependencies_parsed_at":"2022-07-14T12:49:58.706Z","dependency_job_id":null,"html_url":"https://github.com/iftech-engineering/mongo-es","commit_stats":null,"previous_names":["jike-engineering/mongo-es"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iftech-engineering%2Fmongo-es","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iftech-engineering%2Fmongo-es/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iftech-engineering%2Fmongo-es/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iftech-engineering%2Fmongo-es/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iftech-engineering","download_url":"https://codeload.github.com/iftech-engineering/mongo-es/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222031157,"owners_count":16919368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connector","elasticsearch","etl","mongodb"],"created_at":"2024-07-31T12:00:39.723Z","updated_at":"2024-10-29T10:30:48.530Z","avatar_url":"https://github.com/iftech-engineering.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Mongo-ES\n\nA MongoDB to Elasticsearch connector\n\n[![npm version](https://badge.fury.io/js/mongo-es.svg)](https://badge.fury.io/js/mongo-es)\n\n## Installation\n\n```bash\nnpm i -g mongo-es\n```\n\n## Usage\n\n### Command Line\n\n```bash\n# normal mode\nmongo-es ./config.json\n\n# debug mode, with debug info printed\nNODE_ENV=dev mongo-es ./config.json\n```\n\n### Programmatically\n\n```javascript\nconst fs = require('fs')\nconst Redis = require('ioredis')\nconst { Config, Task, run } = require('mongo-es')\n\nconst redis = new Redis('localhost')\n\nTask.onSaveCheckpoint((name, checkpoint) =\u003e {\n  return redis.set(`mongo-es:${name}`, JSON.stringify(checkpoint))\n})\n\n// this will overwrite task.from in config file\nTask.onLoadCheckpoint((name) =\u003e {\n  return redis.get(`mongo-es:${name}`).then(JSON.parse)\n})\n\nrun(new Config(fs.readFileSync('config.json', 'utf8')))\n```\n\n## Concepts\n\n### Scan phase\n\nscan entire database for existed documents\n\n### Tail phase\n\ntail the oplog for documents' create, update or delete\n\n## Configuration\n\nStructure:\n\n```json\n{\n  \"controls\": {},\n  \"mongodb\": {},\n  \"elasticsearch\": {},\n  \"tasks\": [\n    {\n      \"extract\": {},\n      \"transform\": {},\n      \"load\": {}\n    }\n  ]\n}\n```\n\n[Detail example](https://github.com/jike-engineering/mongo-es/blob/master/examples/config.json)\n\n### controls\n\n- `mongodbReadCapacity` - Max docs read per second (default: `10000`). (optional)\n- `elasticsearchBulkInterval` - Max bluk interval per request (default: `5000`). (optional)\n- `elasticsearchBulkSize` - Max bluk size per request (default: `5000`). (optional)\n- `indexNameSuffix` - Index name suffix, for index version control. (optional)\n\n### mongodb\n\n- `url` - The connection URI string, eg: `mongodb://user:password@localhost:27017/db?replicaSet=rs0`.\n  **notice**: must use a `admin` user to access oplog.\n- `options` - Connection settings, see: [MongoClient](http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html#.connect). (optional)\n\n### elasticsearch\n\n- `options` - Elasticsearch Config Options, see: [Configuration](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html).\n- `indices` - If set, auto create indices when program start, see: [Indeces Create](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-0.html#api-indices-create-5-0). (optional)\n\n### task.from\n\n- `phase` - `scan` or `tail`\n- `time` - tail oplog with query: `{ ts: { $gte: new Timestamp(0, new Date(time).getTime() / 1000) } }`\n- `id` - scan collection with query `{ _id: { $gte: id }}`\n\n### task.extract\n\n- `db` - Database name.\n- `collection` - Collection name in database.\n- `projection` - Projection selector, see [Projection](https://docs.mongodb.com/manual/reference/operator/projection/).\n\n### task.transform\n\n- `mapping` - The field mapping from mongodb's collection to elasticsearch's index.\n- `parent` - The field in mongodb's collection to use as the `_parent` in elasticsearch's index. (optional)\n\n### task.load\n\n- `index` - The name of the index.\n- `type` - The name of the document type.\n- `body` - The request body, see [Put Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/indices-put-mapping.html).\n\n## License\n\n[Mozilla Public License Version 2.0](https://www.mozilla.org/en-US/MPL/2.0/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiftech-engineering%2Fmongo-es","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiftech-engineering%2Fmongo-es","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiftech-engineering%2Fmongo-es/lists"}