mongodb-tail

Tool for MongoDB to tail capped collection using MongoDB Native NodeJS Driver

3 years after

mongodb-tail

Tool for MongoDB to tail capped collection using MongoDB Native NodeJS Driver

require("mongodb-tail")(collection, query, [options])

Tail collection:

@param {object} collection - MongoDB collection
@param {build} build - Function to build MongoDB query
@param {object} [options] - Options
@param {number} [options.numberOfRetries=Number.MAX_VALUE]
@param {number} [options.tailableRetryInterval=1000]
@param {number} [options.errorTimeout=1000]
@returns {tail} tail - Instance of EventEmitter

Build:

@typedef {function} build - Function to build MongoDB query
@param {object} latest - Latest document
@returns {object} - MongoDB query

Tail:

@typedef {object} tail - Instance of EventEmitter 
@fires error - On error
@fires next - On cursor next document

Example:

const mongodb = require('mongodb');
const tail = require('mongodb-tail');
mongodb.connect('mongodb://localhost:27017/local?replicaSet=rs')
  .then((db) => {
    tail(
      db.collection('oplog.rs'),
      (latest) => ({ 
        ts: { $gt: latest.ts }, 
        fromMigrate: { $exists: false }, 
        ns: 'test.test', 
        op: { 
          $in: ['i', 'u', 'd'] 
        } 
      })
    )
      .on('error', (err) => console.error(err))
      .on('next', (item) => console.log(item));
  })
  .catch((err) => (console.error(err), process.exit(1)));

Related Repositories

mosql

mosql

MongoDB → PostgreSQL streaming replication ...

cap-recipes

cap-recipes

Battle-tested capistrano recipes for ruby, rubygems, apache, passenger, delayed_ ...

atbat-mongodb

atbat-mongodb

A Perl project that pulls data from MLB's AtBat servers and shoves them into a l ...

cap-recipes

cap-recipes

Battle-tested capistrano recipes for ruby, rubygems, apache, passenger, delayed_ ...

gtm

gtm

gtm (go tail mongo) is a mongodb event listener ...