Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

mongohooks

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongohooks

A thin before/after filter extension for the mongojs node-module

Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

MongoHooks

A thin before/after filter extension for the mongojs node-module.

Install

npm install mongohooks

Usage

var db = require('mongojs')('mydb', ['mycollection']);
var mongohooks = require('mongohooks');

// Add a before filter to db.mycollection.save
mongohooks(db.mycollection).onSave(function (document, next) {...});

// Add a before filter to db.mycollection.insert
mongohooks(db.mycollection).onInsert(function (document, next) {...});

// Add a before filter to db.mycollection.update
mongohooks(db.mycollection).onUpdate(function (query, <update>, next) {...});

// Add a before filter to db.mycollection.onFind
mongohooks(db.mycollection).onFind(function (criteria, <projection>, next) {...});

// Add an after filter to db.mycollection.find and db.mycollection.findOne
// The after filter is called once for each document in a returned result.
mongohooks(db.mycollection).onDocument(function (document, next) {...});

// Filters are async: Call the `next` callback when you are done
mongohooks(db.mycollection).onFind(function (criteria, next) {
  // do stuff
  next();
});

// Before-filters can abort the execution by passing on an error
mongohooks(db.mycollection).onFind(function (criteria, next) {
  next(new Error());
});

// After-filters can also parse on errors
mongohooks(db.mycollection).onDocument(function (document, next) {
  next(new Error());
});

// Filters can be changed and multiple filters of the same type can be added
mongohooks(db.mycollection)
  .onUpdate(function (query, <update>, next) {...})
  .onFind(function (criteria, <projection>, next) {...})
  .onFind(function (criteria, <projection>, next) {...})
  .onDocument(function (document, next) {...});

// Now just use the reqular mongojs API
db.mycollection.find({ ... }, function (err, res) {...});

License

MIT

Keywords

mongo

FAQs

Package last updated on 27 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts