A MongoDB transport for winston logging library, enabling persistent log storage in MongoDB collections. Current stable version is 7.0.1, supporting winston 3.x and mongodb driver 3.x+. Requires Node.js >=14.20.1. Alternative to other winston transports with capped collection support, TTL indexes, and flexible database connection options (URI, pre-connected client, or promise). Includes TypeScript definitions.
npm install winston-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup with a pre-connected MongoClient, logger creation, and entry logging.
Migrate to mongodb driver 3.0+ and winston 3.0+. Pass pre-connected MongoClient or a promise that resolves to one.
Create MongoClient externally and pass it: `new MongoClient(uri); await client.connect(); transport.db = client;`
Always pass a pre-connected MongoClient object to `db`.
Set `leaveConnectionOpen: true` when passing externally managed MongoClient, and close client yourself after logger is done.
Use `require('winston-mongodb')` instead of `import 'winston-mongodb'` to ensure side effects.Run `npm install winston-mongodb` and ensure you are using `require('winston-mongodb')`Use `require('winston-mongodb')` which triggers side effectsVerify MONGO_URI environment variable or pass correct URI to MongoClient; ensure server is running and accessible
Ensure `db` option is a MongoClient instance, not a Db instance. The transport expects a client to call `.collection()`.