Registry / storage / bunyan-mongodb

bunyan-mongodb

JSON →
library1.2.3jsnpmunverified

bunyan-mongodb v1.2.3 (latest as of 2025) provides a MongoDB stream for Bunyan logger. It allows logging directly to a MongoDB collection with optional batch writes. Requires bunyan as a peer dependency. Compared to other MongoDB logging solutions, it integrates seamlessly with Bunyan's stream API. Last released 3 years ago, known as stable but not actively maintained. Ships TypeScript definitions.

npm install bunyan-mongodb
INSTALL
IMPORT
SIG · BUNYAN-MONGODB
B
bunyan-mongodb
storagejavascriptv1.2.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.

bunyanMongo
const bunyanMongo = require('bunyan-mongodb');
import bunyanMongo from 'bunyan-mongodb'; // ESM not supported
Package uses CommonJS; do not use ESM import. For TypeScript, use require or configure esModuleInterop.
bunyan
const bunyan = require('bunyan');
Bunyan is a required peer dependency.
MongoStreamOptions
import type { MongoStreamOptions } from 'bunyan-mongodb';
TypeScript types are bundled; use this for option type annotations.

Creates a Bunyan logger that writes to MongoDB using bunyan-mongodb. Requires bunyan as peer dependency. Uses environment variables for credentials.

const bunyan = require('bunyan'); const bunyanMongo = require('bunyan-mongodb'); const logger = bunyan.createLogger({ name: 'myApp', streams: [ { level: 'info', stream: bunyanMongo({ host: process.env.MONGO_HOST ?? 'localhost', database: process.env.MONGO_DB ?? 'logs', collection: 'app_log', username: process.env.MONGO_USER ?? '', password: process.env.MONGO_PASS ?? '', batchSize: 50 }) } ] }); logger.info('Hello Mongo!');
Debug
Known issues
gotchabatchSize defaults to 1 if not specified, causing individual inserts instead of batches.
fix
Set batchSize to a reasonable value (e.g., 100) to avoid performance issues.
affects: >=1.0.0
deprecatedPackage uses native MongoDB driver v2; may not be compatible with MongoDB 5+ features.
fix
Consider alternatives like winston-mongodb or upgrade to a maintained fork.
affects: >=1.0.0
gotchaIf authentication database is not provided, it defaults to 'admin'. Missing authDatabase can cause authentication failures.
fix
Explicitly set authDatabase if using non-admin credentials.
affects: >=1.0.0
breakingRequires bunyan as peer dependency; not installing bunyan will cause runtime error.
fix
npm install bunyan as a dependency.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bunyan'
bunyan is a peer dependency not installed.
fix
npm install bunyan
TypeError: bunyanMongo is not a function
Default import used with ESM; package is CommonJS.
fix
const bunyanMongo = require('bunyan-mongodb');
MongoError: Authentication failed.
authDatabase not set or wrong credentials.
fix
Provide correct authDatabase (default 'admin') in options.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies
bunyanrequiredbunyan-mongodb is a stream for bunyan logger, must be installed as peer
Agent activity
34 hits · last 30 days
node
30
Resources
bunyan-mongodb — npm install bunyan-mongodb · libregistry