A Event Emitter to subscribe for changes in a MongoDB ReplicaSet
yarn add @funjs/mongo-emitter
or
npm install --save @funjs/mongo-emitter
const Emitter = require('@funjs/mongo-emitter');
const mongo = MongoEmitter('mongo://localhost:27017/my-db');
mongo.on('users/:action=(insert|update)/:id', ({ action, id }, data) => {
console.log(`action: ${action}`);
console.log(`id: ${id}`);
console.log(`data: ${JSON.stringify(data)}`);
});
// action: insert
// id: 1
// data: {"_id":1,"name":"Joe","age":33}
// action: update
// id: 1
// data: {"_id":1,"name":"Joe","age":34}
// action: remove
// id: 1
// data: {"_id": 1}
// ...
- [] Basic API
- [] Implement
mongo query api
to subscribe to more specific changes