Process your mongodb oplog as events
The mongodb driver has added this feature in version 3. There's no reason any more to use this library, so it has therefore been archived.
The module connects to a mongodb oplog and emits all of the transactions as a nodejs event emitter. This provides a much nicer high level API to work with.
All events are emitted as an op
event. Insert, update and delete events are available as insert
, update
and delete
respectively.
The module can authenticate in the admin database using username/password and allows you to pass in a custom last processed timestamp. If this is not provided, it will only emit events that occurred after the module connected to mongodb.
$ npm install oplog-emitter
let OplogEmitter = require('oplog-emitter');
let emitter = new OplogEmitter('mongodb://myuser:password@localhost:27000/local?authSource=admin')
emitter.on('insert', (op) => console.log(`${op} was inserted`))
- Allow more mongodb authentication mechanisms
Apache-2.0 © Wouter Dullaert
An object containing the configuration options of the OplogEmitter
Properties
oplogURL
string A mongodb connection string to the oploggetLastTimestamp
?TimestampGenerator A function returning a mongodb Timestamp with the starting offset in the oplogdatabase
?string Filter oplog events by this database namecollection
?string Filter oplog events by this collection namecredentials
?Credentials An object of mongodb credentialsretries
?number The amount of times to retry connecting to the database (with exponential-backoff)log
?function A function which this library can use to logtimestampTimeout
?number The number of milliseconds we should wait for getLastTimestamp to return a result
An object with mongodb credentials of a user in the admin database
Properties
A function returning a promise to a mongodb Timestamp
Returns Promise<Timestamp> A promise resolving to a mongodb timestamp
Extends EventEmitter
An event emitter that fires for every oplog entry
Parameters
args
(string | OplogOptions) constructor options
Examples
let OplogEmitter = require('oplog-emitter');
let emitter = new OplogEmitter('mongodb://localhost:27017/local?authSource=admin');
emitter.on('op', () => console.log('A transaction was added to the oplog'));
emitter.on('insert', () => console.log('An insert was done in the database'));
emitter.on('delete', () => console.log('A document was deleted in the database'));
emitter.on('update', () => console.log('A document was updated in the database'));
emitter.on('error', () => console.log('Something went wrong when reading'));
- Throws TypeError when constructor arguments are not valid