Skip to content

Event Emitter to subscribing for changes in a MongoDB ReplicaSet

License

Notifications You must be signed in to change notification settings

fun-js/mongo-emitter

Repository files navigation

travis build Dependency Status devDependency Status Codecov MIT License

What is it?

A Event Emitter to subscribe for changes in a MongoDB ReplicaSet

How do I install it?

yarn add @funjs/mongo-emitter
or
npm install --save @funjs/mongo-emitter

How do I use it?

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}

// ...

TODO:

  • [] Basic API
  • [] Implement mongo query api to subscribe to more specific changes

About

Event Emitter to subscribing for changes in a MongoDB ReplicaSet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published