1.0.1 • Published 4 years ago

opswatcher v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

opswatcher

helper for watching ops log in mongoDB for changes in a collection or all changes

Usage

Typescript

// Typescript
import Watcher from 'opswatcher';
// node JS
const Watcher = require('opswatcher').default;
const uri = 'mongodb+srv://username:password@host/database';
const watcher = new Watcher(uri);
watcher.connect().then(() => {
    // get an event emitter for test collection
    const test = watcher.addWatcher('test');
    test.on('data', (doc) => {
        console.log('test watcher', doc);
    });
    watcher.watch();
});

If you wish to start watching from an earler date you can pass a date into the constructer

const watcher = new Watcher(uri, new Date('2020-04-08 11:33:48'));

You can also access the every change with

const watcher = new Watcher(uri);

watcher.global.on('data | error | close | end');