{"id":43142,"library":"mongodb-datadog-stats","title":"MongoDB Datadog Stats","description":"This package hooks into the MongoDB Node.js driver to automatically record query performance metrics as Datadog histograms. Current stable version is 0.1.2, last updated in 2014. It patches the driver's methods to measure execution time and emit stats to a StatsD client. No longer actively maintained; users are advised to consider alternatives like datadog-metrics or custom APM libraries for modern MongoDB drivers.","status":"maintenance","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/suprememoocow/node-mongodb-datadog-stats","tags":["javascript","mongodb","datadog","performance","metrics"],"install":[{"cmd":"npm install mongodb-datadog-stats","lang":"bash","label":"npm"},{"cmd":"yarn add mongodb-datadog-stats","lang":"bash","label":"yarn"},{"cmd":"pnpm add mongodb-datadog-stats","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: patches the driver's prototype to instrument query methods","package":"mongodb","optional":true}],"imports":[{"note":"Package is CommonJS-only; ESM import will fail. Use require().","wrong":"import mongoDogStats from 'mongodb-datadog-stats';","symbol":"default (install function)","correct":"const mongoDogStats = require('mongodb-datadog-stats');"},{"note":"install is a plain function, not a constructor.","wrong":"new mongoDogStats.install(mongodb, {...});","symbol":"install function","correct":"mongoDogStats.install(mongodb, { statsClient, metric, sampleRate });"},{"note":"Available to remove instrumentation; rarely used but exported.","wrong":"","symbol":"Uninstall function","correct":"mongoDogStats.uninstall(mongodb);"}],"quickstart":{"code":"const mongodb = require('mongodb');\nconst mongoDogStats = require('mongodb-datadog-stats');\nconst StatsD = require('hot-shots'); // or node-statsd\n\nconst statsClient = new StatsD({ host: 'localhost', port: 8125 });\n\nmongoDogStats.install(mongodb, {\n  statsClient: statsClient,\n  metric: 'mongodb.query',\n  sampleRate: 0.5\n});\n\n// Now all MongoClient operations are instrumented\n// e.g. db.collection('test').findOne({}, (err, doc) => {\n//   // query time automatically reported to Datadog as histogram\n// });","lang":"javascript","description":"Instruments the MongoDB driver to send query performance histograms to Datadog via StatsD."},"warnings":[{"fix":"Upgrade to a more recent instrumentation library like 'mongodb-instrumentor' or use Datadog APM.","message":"Requires mongodb < 3.0 (driver v2.x). Does not work with mongodb >= 3.0 due to major changes in the driver API.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Consider switching to 'datadog-metrics' or 'hot-shots' with manual instrumentation.","message":"Package is no longer maintained and has not been updated since 2014.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Call install() only once per process, passing a single statsClient.","message":"Patches the mongodb module globally; calling install() multiple times with different clients may cause unexpected behavior.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use callback-style or manually wrap with promisify if needed.","message":"Does not support promises or async/await; only works with callback-based operations.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.2':25 '2014':29 'activ':49 'advis':53 'altern':56 'apm':63 'automat':13 'client':46 'consid':55 'current':21 'custom':62 'datadog':2,19,59,71 'datadog-metr':58 'driver':11,33,68 'emit':41 'execut':38 'histogram':20 'hook':6 'javascript':69 'last':26 'librari':64 'like':57 'longer':48 'maintain':50 'measur':37 'method':35 'metric':17,60,73 'modern':66 'mongodb':1,9,67,70 'node.js':10 'packag':5 'patch':31 'perform':16,72 'queri':15 'record':14 'stabl':22 'stat':3,42 'statsd':45 'time':39 'updat':27 'user':51 'version':23","created_at":"2026-06-05T16:58:23.039312+00:00","updated_at":"2026-06-05T16:58:23.039312+00:00","problems":[{"fix":"Install via `npm install mongodb-datadog-stats` and use `require()` (CommonJS).","cause":"Package not installed or incorrectly imported in ESM context.","error":"Error: Cannot find module 'mongodb-datadog-stats'"},{"fix":"Use `const mongoDogStats = require('mongodb-datadog-stats');` instead of `import`.","cause":"Using ES6 import statement incorrectly on a CommonJS module.","error":"TypeError: mongoDogStats.install is not a function"},{"fix":"Use mongodb driver version 2.x (e.g., `npm install mongodb@2`).","cause":"Passing a newer version of mongodb where the driver's internal structure changed.","error":"TypeError: Cannot read property 'prototype' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/suprememoocow/node-mongodb-datadog-stats","github":"https://github.com/suprememoocow/node-mongodb-datadog-stats","docs":null,"changelog":null,"pypi":null,"npm":"mongodb-datadog-stats","openapi_spec":null,"status_page":null,"smithery":null,"categories":["analytics","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}