Registry / database / mongodb-perf-wrapper

mongodb-perf-wrapper

JSON →
library0.1.3jsnpmunverified

Monkey-patches node-mongodb-native to capture query performance metrics. Wraps the mongodb driver so every operation (find, insert, update, remove) reports duration in microseconds via a callback. Unwraps cleanly. Version 0.1.3 (latest) – no updates since 2014, stable for its narrow use case. Lightweight with no runtime dependencies beyond mongodb itself. Not compatible with mongodb@3+ due to internal API changes.

npm install mongodb-perf-wrapper
INSTALL
IMPORT
SIG · MONGODB-PERF-WRAPP
M
mongodb-perf-wrapper
databasejavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wrapper.wrap
const wrapper = require('mongodb-perf-wrapper'); wrapper.wrap(mongodb, callback);
import { wrap } from 'mongodb-perf-wrapper';
Only CommonJS require works; no ESM support. The function is exported as a single object, not named exports.
wrapper.unwrap
wrapper.unwrap(mongodb);
wrapper.unwrap();
Must pass the same mongodb instance that was wrapped to properly restore original methods.
mongodb (driver instance)
const mongodb = require('mongodb'); wrapper.wrap(mongodb, cb);
const client = new MongoClient(...); wrapper.wrap(client, cb);
The wrapper works on the top-level mongodb module, not on a client instance. It patches the prototype methods.

Demonstrates wrapping the mongodb module to log performance metrics for every operation and then cleanly unwrapping.

var mongodb = require('mongodb'); var wrapper = require('mongodb-perf-wrapper'); // Wrap all operations with a performance callback wrapper.wrap(mongodb, function(collection, operation, timeMicroSeconds, query, responseErr) { console.log('Operation:', operation, 'took', timeMicroSeconds, 'µs'); }); // Use mongodb normally mongodb.MongoClient.connect('mongodb://localhost:27017/test', function(err, db) { if (err) return console.error(err); db.collection('test').insert({a:1}, function() { db.close(); }); }); // Unwrap after 5 seconds setTimeout(function() { wrapper.unwrap(mongodb); }, 5000);
Debug
Known issues
gotchaMonkey-patches the global mongodb module; may conflict with other wrappers or cause unexpected behavior in concurrent operations.
fix
Use only once per process; consider isolating mongodb usage if multiple libraries patch it.
affects: *
breakingNot compatible with node-mongodb-native v3+ because internal method signatures changed (e.g., callback arguments).
fix
Pin mongodb driver to version ^2.x.
affects: >=0.3.0
deprecatedNo updates since 2014; the package is effectively unmaintained and may have hidden issues with modern Node.js versions.
fix
Consider migrating to a maintained alternative like 'mongodb-query-analyzer' or use APM tools.
affects: *
gotchaThe callback receives 'collection' as a string, not the actual Collection object; be careful not to assume it's an object.
fix
Treat collection parameter as string name.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read property 'prototype' of undefined
Passing a MongoClient instance instead of the top-level mongodb module.
fix
Use the require('mongodb') result, not a database connection.
wrapper.unwrap is not a function
Attempting to use ESM import syntax (import wrapper from 'mongodb-perf-wrapper') which returns an empty object.
fix
Use CommonJS require: const wrapper = require('mongodb-perf-wrapper');
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency; wraps the mongodb driver. Must be version ^2.x for compatibility.
Agent activity
12 hits · last 30 days
node
10
Resources
mongodb-perf-wrapper — npm install mongodb-perf-wrapper · libregistry