mongo-watch
Advanced tools
| {getTimestamp} = require './util' | ||
| connect = require './connect' | ||
| module.exports = ({host, port, dbOpts, username, password}, done) -> | ||
| module.exports = ({host, port, dbOpts, username, password, useMasterOplog}, done) -> | ||
| connect {db: 'local', host, port, dbOpts, username, password}, (err, oplogClient) => | ||
| return done new Error "Error connecting to database: #{err}" if err | ||
| oplogClient.collection 'oplog.rs', (err, oplog) -> | ||
| collection = 'oplog.rs' | ||
| if useMasterOplog | ||
| collection = 'oplog.$main' | ||
| oplogClient.collection collection, (err, oplog) -> | ||
| return done err if err | ||
@@ -10,0 +13,0 @@ |
+1
-0
@@ -12,2 +12,3 @@ {EventEmitter} = require 'events' | ||
| options.format or= 'raw' | ||
| options.useMasterOplog or= false | ||
| options.convertObjectIDs ?= true | ||
@@ -14,0 +15,0 @@ options.onError or= (error) -> console.log 'Error - MongoWatch:', (error?.stack or error) |
+1
-1
| { | ||
| "name":"mongo-watch", | ||
| "description":"A mongo watcher. This ties into the MongoDB replication oplog, and exposes all data modifications via an EventEmitter.", | ||
| "version":"0.2.6", | ||
| "version":"0.2.7", | ||
| "homepage":"http://github.com/TorchlightSoftware/mongo-watch", | ||
@@ -6,0 +6,0 @@ "repository":"git://github.com/TorchlightSoftware/mongo-watch.git", |
+10
-2
| # Mongo Watch | ||
| This watcher ties into the MongoDB replication log (local.oplog.rs) and notifies your watchers any time the data changes. | ||
| This watcher ties into the MongoDB replication log (local.oplog.rs) by default, but you can also tie into local.oplog.$main on a master DB. It then notifies your watchers any time the data changes. | ||
| In order to use this you must: | ||
| *replication log* | ||
| 1. Have access to the oplog. This will not be available on shared DB hosting, as it would reveal everyone else's database transactions to you. | ||
| 2. Have replication enabled. This can be done by starting mongod with the option '--replSet someArbitraryName'. You must then call `rs.initiate()` from the mongo CLI. | ||
| 2. Have replication enabled. This can be done by starting mongod with the option `--replSet someArbitraryName`. You must then call `rs.initiate()` from the mongo CLI. | ||
| *master log* | ||
| 1. Have access to the oplog. This will not be available on shared DB hosting, as it would reveal everyone else's database transactions to you. | ||
| 2. Start your mongod as `--master`. | ||
| 3. Use: `new MongoWatch({useMasterOplog:true})` | ||
| The watcher is fairly low latency and overhead. On my machine a test with a single insert and watcher takes 20ms. The cursor used to tail the oplog is being initialized with {awaitdata: true} so the data should be getting pushed from MongoDB's internal mechanism, instead of polling. | ||
@@ -11,0 +19,0 @@ |
22976
2.1%140
6.06%