{"_id":"@aestetype/mongo-oplog","_rev":"3-c66cac22d508ab93c58363f09349fb25","name":"@aestetype/mongo-oplog","description":"Watch mongodb oplog in a simple way","dist-tags":{"latest":"2.0.2"},"versions":{"2.0.2":{"name":"@aestetype/mongo-oplog","version":"2.0.2","description":"Watch mongodb oplog in a simple way","author":{"name":"Jonathan Brumley","email":"cayasso@gmail.com"},"homepage":"https://github.com/aestetype/mongo-oplog","main":"./index.js","types":"./src/index.d.ts","scripts":{"test":"xo && mocha","build":"npm run clean && ./node_modules/.bin/babel src -d lib","prepare":"npm run build","clean":"rm -rf lib/"},"repository":{"type":"git","url":"git://github.com/aestetype/mongo-oplog.git"},"keywords":["data","mongo","mongodb","watcher","live","oplog","cursor"],"license":"MIT","dependencies":{"debug":"2.3.x","eventemitter3":"^2.0.2","mongodb":"~2.2.x","babel-polyfill":"^6.20.0"},"devDependencies":{"babel-cli":"^6.18.0","babel-core":"^6.20.0","babel-loader":"^6.2.9","babel-plugin-syntax-async-functions":"^6.13.0","babel-plugin-transform-async-to-generator":"^6.16.0","babel-plugin-transform-es2015-destructuring":"^6.19.0","babel-plugin-transform-object-rest-spread":"^6.20.2","babel-plugin-transform-regenerator":"^6.20.0","babel-plugin-transform-runtime":"^6.15.0","babel-preset-es2015":"^6.18.0","babel-preset-stage-0":"^6.16.0","mocha":"*","pre-commit":"1.2.0","should":"^11.1.1","xo":"^0.17.1"},"pre-commit":["test"],"xo":{"semicolon":false,"esnext":true,"space":2,"ignores":["test/**"],"rules":{"curly":0,"new-cap":0,"no-unused-vars":0,"object-curly-spacing":0,"no-unused-expressions":0,"promise/param-names":0,"import/no-unassigned-import":0,"no-negated-condition":0}},"gitHead":"2664cb053bfb420f42b94bacebe87a2feb9dcdb3","bugs":{"url":"https://github.com/aestetype/mongo-oplog/issues"},"_id":"@aestetype/mongo-oplog@2.0.2","_npmVersion":"5.3.0","_nodeVersion":"8.5.0","_npmUser":{"name":"zadkiel","email":"zadkiel.aharonian@gmail.com"},"dist":{"integrity":"sha512-6QZGQxBtRUeHcbGdlXAQk3jolEZrjEI9cGTp5rY0Ys9PvGjdKCjp+gJNJprdRA5Sve1WG6l33q3oilckyH/EaA==","shasum":"6e5437b88e63c73ba7a74af867e2d21988dbdfe5","tarball":"https://registry.npmjs.org/@aestetype/mongo-oplog/-/mongo-oplog-2.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICHtoXy26ViOgfdnvS8p1CqIKtiMx1Fj1PZou9q93k+aAiBg1tFfV6xRfwJdF2l/NcqfdTWhWAYHJnH/07ZXV8X01w=="}]},"maintainers":[{"name":"zadkiel","email":"zadkiel.aharonian@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongo-oplog-2.0.2.tgz_1507137448468_0.2544188732281327"},"directories":{}}},"readme":"# mongo-oplog\n\n[![Build Status](https://img.shields.io/travis/cayasso/mongo-oplog/master.svg)](https://travis-ci.org/cayasso/mongo-oplog)\n[![NPM version](https://img.shields.io/npm/v/mongo-oplog.svg)](https://www.npmjs.com/package/mongo-oplog)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\nListening to MongoDB live changes using oplog.\n\n## Features\n\n* Support start and stop tailing the MongoDB `oplog` at any time.\n* Support filtering `oplog` events by `namespaces` (database and collections).\n* Built on top of the native NodeJS [MongoDB driver](https://github.com/mongodb/node-mongodb-native/).\n* First class `Promise` support which enable the use of `async` and `await`.\n* The package has a very small footprint and requires just a few dependencies including `mongodb`, `debug` and `eventemitter3`.\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 `v4.x` and `v5.x`.\n\n## IMPORTANT! Major update version 2.0.x\n\n2.0.x is a major rewrite taking advantage of `es6` and adding support for `promises` and `async/await`. Callbacks are still supported for backward compatibility.\nThis version has minimum **API** changes, but these changes might affect your code, so please take a look at the upgrading guide before installing.\n\n[Check the upgrading guide here](https://github.com/cayasso/mongo-oplog/blob/master/UPGRADE.md)\n\n[Go here for the old 1.x readme](https://github.com/cayasso/mongo-oplog/tree/1.x)\n\n[Go here for the old 0.x readme](https://github.com/cayasso/mongo-oplog/tree/0.x)\n\n## Installation\n\n``` bash\n$ npm install mongo-oplog\n```\n\n## Usage\n\n``` javascript\nimport MongoOplog from 'mongo-oplog'\nconst oplog = MongoOplog('mongodb://127.0.0.1:27017/local', { ns: 'test.posts' })\n\noplog.tail();\n\noplog.on('op', data => {\n  console.log(data);\n});\n\noplog.on('insert', doc => {\n  console.log(doc);\n});\n\noplog.on('update', doc => {\n  console.log(doc);\n});\n\noplog.on('delete', doc => {\n  console.log(doc.o._id);\n});\n\noplog.on('error', error => {\n  console.log(error);\n});\n\noplog.on('end', () => {\n  console.log('Stream ended');\n});\n\noplog.stop(() => {\n  console.log('server stopped');\n});\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```javascript\noplog.tail().then(() => {\n  console.log('tailing started')\n}).catch(err => console.error(err))\n\n// or with async/await\nasync function tail() {\n  try {\n    await oplog.tail()\n    console.log('tailing started')\n  } catch (err) {\n    console.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```javascript\noplog.stop().then(() => {\n  console.log('tailing stopped')\n}).catch(err => console.error(err))\n\n// or with async/await\nasync function stop() {\n  try {\n    await oplog.stop()\n    console.log('tailing stopped')\n  } catch (err) {\n    console.log(err)\n  }\n}\n```\n\n### oplog.destroy([fn])\n\nDestroy the `mongo-oplog` object by stop tailing and disconnecting from server.\nThis method support both `Promise` and `callback`.\n\n```javascript\noplog.destroy.then(() => {\n  console.log('destroyed')\n}).catch(err => console.error(err))\n\n// or with async/await\nasync function destroy() {\n  try {\n    await oplog.destroy()\n    console.log('destroyed')\n  } catch (err) {\n    console.log(err)\n  }\n}\n```\n\n### oplog.ignore\n\nPause and resume oplog events.\n\n```javascript\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```javascript\nconst filter = oplog.filter('*.posts')\nfilter.on('op', fn)\noplog.tail()\n```\n\n### filter.destroy()\n\nDestroy filter object.\n\n```javascript\nfilter.destroy()\n```\n\n### filter.ignore\n\nPause and resume filter events.\n\n```javascript\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:\n\nStart MongoDB with:\n\n```bash\n$ mongod --replSet test\n```\n\nStart a `mongo` shell and configure mongo as follows:\n\n```bash\n$ mongo\n> var config = {_id: \"test\", members: [{_id: 0, host: \"127.0.0.1:27017\"}]}\n> rs.initiate(config)\n```\n\nOnce configuration is initiated then you can run the test:\n\n``` bash\n$ npm install\n$ npm run test\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2015 Jonathan Brumley &lt;cayasso@gmail.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"email":"pradel.leo@gmail.com","name":"leopradel"},{"email":"zadkielhello@gmail.com","name":"zadkiel"}],"time":{"modified":"2022-04-04T11:49:39.887Z","created":"2017-10-04T17:17:29.683Z","2.0.2":"2017-10-04T17:17:29.683Z"},"homepage":"https://github.com/aestetype/mongo-oplog","keywords":["data","mongo","mongodb","watcher","live","oplog","cursor"],"repository":{"type":"git","url":"git://github.com/aestetype/mongo-oplog.git"},"author":{"name":"Jonathan Brumley","email":"cayasso@gmail.com"},"bugs":{"url":"https://github.com/aestetype/mongo-oplog/issues"},"license":"MIT","readmeFilename":"README.md"}