Skip to content

Commit

Permalink
Fixed bug leading to multiple emits for the same collection.
Browse files Browse the repository at this point in the history
Lowercase name for npm registry.
Tweaked example.
  • Loading branch information
benjaminkitt committed Sep 25, 2014
1 parent 4da16df commit 9833a36
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Many of the options are similar to Mongo Watch, but the connection options have

To install oploggery from npm, run:

> `npm install Oploggery`
> `npm install oploggery`
# Usage

Expand Down
6 changes: 4 additions & 2 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var Oploggery = require('../index.js');

var oplogger = new Oploggery({
uri: 'mongodb://localhost:27017/test'
uri: 'mongodb://localhost:27017/hrDataTest'
});
oplogger.watch();
oplogger.watch('test.users', function(data) {
console.log(data);
});
40 changes: 21 additions & 19 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,29 @@ Oploggery = (function() {
notify = notify || console.log;

this.ready(function() {
var watcher = function(data) {
var channel, event, formatter, relevant;

relevant = (collection === 'all') || (data.ns === collection);
if (!relevant) {
return;
}

channel = collection ? "change:" + collection : 'change';
formatter = formats[this.options.format] || formats.raw;
event = formatter(data);
if (this.options.convertObjectIDs === true) {
event = walk(event, convertObjectID);
}
return this.channel.emit(collection, event);
}.bind(this);
this.stream.on('data', watcher);
this.watching[collection] = watcher;
if (!this.watching[collection]) {
var watcher = function(data) {
var channel, event, formatter, relevant;

relevant = (collection === 'all') || (data.ns === collection);
if (!relevant) {
return;
}

channel = collection ? "change:" + collection : 'change';
formatter = formats[this.options.format] || formats.raw;
event = formatter(data);
if (this.options.convertObjectIDs === true) {
event = walk(event, convertObjectID);
}
this.channel.emit(collection, event);
}.bind(this);
this.stream.on('data', watcher);
this.watching[collection] = watcher;
}

}.bind(this));
return this.channel.on(collection, notify);
this.channel.on(collection, notify);
};

Oploggery.prototype.stop = function(collection) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Oploggery",
"version": "0.1.0",
"name": "oploggery",
"version": "0.1.1",
"description": "A MongoDB oplog watcher for Node.js",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 9833a36

Please sign in to comment.