{"id":18554572,"url":"https://github.com/jasancheg/x-mongo-db-live-changes","last_synced_at":"2026-04-16T18:03:05.676Z","repository":{"id":152669029,"uuid":"121153327","full_name":"jasancheg/x-mongo-db-live-changes","owner":"jasancheg","description":"Watch Mongo DB live changes","archived":false,"fork":false,"pushed_at":"2018-02-11T18:42:49.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-15T12:08:42.037Z","etag":null,"topics":["db-api","mongodb","nodejs","real-time","replication"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasancheg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-11T18:24:41.000Z","updated_at":"2018-02-11T18:29:30.000Z","dependencies_parsed_at":"2023-05-09T17:01:05.752Z","dependency_job_id":null,"html_url":"https://github.com/jasancheg/x-mongo-db-live-changes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jasancheg/x-mongo-db-live-changes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasancheg%2Fx-mongo-db-live-changes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasancheg%2Fx-mongo-db-live-changes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasancheg%2Fx-mongo-db-live-changes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasancheg%2Fx-mongo-db-live-changes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasancheg","download_url":"https://codeload.github.com/jasancheg/x-mongo-db-live-changes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasancheg%2Fx-mongo-db-live-changes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31897870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T17:33:00.867Z","status":"ssl_error","status_checked_at":"2026-04-16T17:32:57.401Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["db-api","mongodb","nodejs","real-time","replication"],"created_at":"2024-11-06T21:22:47.606Z","updated_at":"2026-04-16T18:03:05.640Z","avatar_url":"https://github.com/jasancheg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# x-db-oplog\n\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\n\n\u003e Version: 0.1.0.\n\u003e\n\u003e Updated: Feb 11, 2018. 12:31 pm UTC-6\n\u003e\n\u003e Status: completed\n\n\nListening to MongoDB live changes using oplog in a simple way.\n\n## Features\n\n* The package has a very small footprint and requires just a few dependencies including `mongodb`, `debug` and `eventemitter3`.\n* Built on top of the native NodeJS [MongoDB driver](https://github.com/mongodb/node-mongodb-native/).\n* Support start and stop tailing the MongoDB `oplog` at any time.\n* Support filtering `oplog` events by `namespaces` (database and collections).\n* First class `Promise` support which enable the use of `async` and `await`.\n* Uses `eventemitter3` for high performance event emitting.\n* Strict and readable code enforced with [xo](https://github.com/sindresorhus/xo)\n* Unit tested with `mocha` and built with `babel` for backward compatibility with older versions of NodeJS like `v6.x` and `v7.x`.\n\n\n## Installation\n\n``` bash\n$ npm install https://github.com/jasancheg/x-mongo-db-live-changes.git\n```\n\n## Configure MongoDB with replica set\n\nYou need to configure your MongoDB instance (local instance) to have access to the [oplog](https://docs.mongodb.com/manual/core/replica-set-oplog/), here are some quick steps on how to do so:\n\n1. Shutdown your existing mongo instance if its running.\n\n2. Restart the instance. Use the `--replSet` option to specify the name of the replica set.\n\n``` bash\n$ sudo mongod --replSet rs0\n```\n\n3. Connect to the mongo instance by executing `mongo` in your terminal:\n\n```bash\n$ mongo\n```\n\n4. In the mongo shell run `rs.initiate()` to initiate the new replica set:\n\n```bash\n\u003e rs.initiate()\n```\n\nOnce it is initiated then you are ready to start using `x-db-oplog`.\n\nAnd [here is the official MongoDB documentation](https://docs.mongodb.com/manual/tutorial/convert-standalone-to-replica-set/) if you need additional help on MongoDB replica set.\n\n## Usage\n\n```js\nconst MongoOplog = require('x-db-oplog');\nconst oplog = MongoOplog('mongodb://127.0.0.1:27017/local', { ns: 'test.news' });\nconst { log } = console;\n\noplog.tail();\n\noplog.on('op', data =\u003e log(data));\noplog.on('insert', doc =\u003e log(doc));\noplog.on('update', doc =\u003e log(doc));\noplog.on('delete', doc =\u003e log(doc.o._id));\noplog.on('error', error =\u003e log(error));\noplog.on('end', () =\u003e log('Stream ended'));\noplog.stop(() =\u003e log('server stopped'));\n```\n\n## API\n\n### MongoOplog(uri, [options])\n\n* `uri`: Valid MongoDB uri or a MongoDB server instance.\n* `options` MongoDB connection options.\n\n### oplog.tail([fn])\n\nStart tailing.\nThis method support both `Promise` and `callback`.\n\n```js\nconst { log, error } = console\n\noplog.tail()\n  .then(() =\u003e log('tailing started'))\n  .catch(err =\u003e error(err))\n\n// or with async/await\nasync function tail() {\n  try {\n    await oplog.tail()\n    log('tailing started')\n  } catch (err) {\n    log(err)\n  }\n}\n```\n\n### oplog.stop([fn])\n\nStop tailing and disconnect from server.\nThis method support both `Promise` and `callback`.\n\n```js\nconst { log, error } = console\n\noplog.stop()\n  .then(() =\u003e log('tailing stopped'))\n  .catch(err =\u003e error(err))\n\n// or with async/await\nasync function stop() {\n  try {\n    await oplog.stop()\n    log('tailing stopped')\n  } catch (err) {\n    log(err)\n  }\n}\n```\n\n### oplog.destroy([fn])\n\nDestroy the `x-db-oplog` object by stop tailing and disconnecting from server.\nThis method support both `Promise` and `callback`.\n\n```js\nconst { log, error } = console\n\noplog.destroy\n  .then(() =\u003e log('destroyed'))\n  .catch(err =\u003e error(err))\n\n// or with async/await\nasync function destroy() {\n  try {\n    await oplog.destroy()\n    log('destroyed')\n  } catch (err) {\n    error(err)\n  }\n}\n```\n\n### oplog.ignore\n\nPause and resume oplog events.\n\n```js\noplog.ignore = true; // to pause\noplog.ignore = false // to resume\n```\n\n### oplog.filter(ns)\n\nCreate and return a filter object.\n\n```js\nconst filter = oplog.filter('*.news')\nfilter.on('op', fn)\noplog.tail()\n```\n\n### filter.destroy()\n\nDestroy filter object.\n\n```js\nfilter.destroy()\n```\n\n### filter.ignore\n\nPause and resume filter events.\n\n```js\nfilter.ignore = true; // to pause\nfilter.ignore = false // to resume\n```\n\n### events\n\nEvents supported by `oplog` and `filter`;\n\n* `op`: All bellow operations (oplog/filter).\n* `insert`: Document insert (oplog/filter).\n* `update`: Document update (oplog/filter).\n* `delete`: Document delete (oplog/filter).\n* `end`: Cursor stream ended (oplog).\n* `error`: Error (oplog).\n\n## Run tests\n\nConfigure MongoDB for active oplog, once this is done then you can run the test:\n\n``` bash\n$ npm install\n$ npm run test\n```\n\n\n## License\n\n© 2018 MIT License.  Made with ♥️  -  🇨🇷 - [Inidea](http://inideaweb.com) - [Tonisan](http://tonisan.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasancheg%2Fx-mongo-db-live-changes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasancheg%2Fx-mongo-db-live-changes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasancheg%2Fx-mongo-db-live-changes/lists"}