Giter Club home page Giter Club logo

node-mongodb-watcher's Introduction

Monitor your mongodb connection for bad queries in the client-side.

Installation

npm i mongodb-watcher

Usage

//connect to mongodb
const watcher = new MongoWatcher(db, {
  longCursorThreshold:  100,
  largeInsertThreshold: 1024 * 30,
  largeFetchThreshold:  1024 * 30
});

watcher.on('long.cursor.enumeration', (data) => {
  logger.error(`Detected bad query over ${data.collection} returning ${data.count} documents. \n ${data.stack}`);
});

db.collection('apples').find().toArray((apples) => {
  res.json(apples);
});

Events

long.cursor.enumeration

This event is emitted when a cursor is enumerated (.toArray) returning an array of documents with more than longCursorThreshold (defaults 100).

The data of the event contains:

  • collection: the name of the collection
  • count: the number of documents returned or inserted
  • stack: an stack trace of to identify where the call was made
  • cmd: it contains the query, limit, skip, readPreference, slaveOk, etc.

large.document.insert

This event is emitted when calling .insert([]) or .save with a document of size greater than bigInsertThreshold (defaults 30k).

  • collection: the name of the collection
  • documentId: the document._id value
  • size: the size of the doc in bytes
  • cmd: it contains the query, limit, skip, readPreference, slaveOk, etc
  • stack: an stack trace of to identify where the call was made

large.document.fetch

This event is emitted when retrieving a big document from the database.

  • collection: the name of the collection
  • documentId: the document._id value
  • size: the size of the doc in bytes
  • stack: an stack trace of to identify where the call was made

More events are welcome.

License

MIT 2016 . JOSE F. ROMANIELLO

node-mongodb-watcher's People

Contributors

jfromaniello avatar siacomuzzi avatar ziluvatar avatar

Watchers

James Cloos avatar 叶摇 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.