{"id":43624,"library":"pino-mongodb","title":"pino-mongodb","description":"Pino transport for inserting structured JSON logs into MongoDB. Current stable version is 5.0.0, released in 2024. This package is part of the Pino logger ecosystem and supports both modern Pino transports and legacy CLI usage. It allows users to pipe log streams directly into MongoDB collections, with options for custom parsing and authentication. Compared to other MongoDB log transports, it integrates seamlessly with Pino's pipeline and can handle high-throughput logging. The library is actively maintained with frequent releases.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/pinojs/pino-mongodb","tags":["javascript","pino","mongo","mongodb","pino-mongodb","logs","logger"],"install":[{"cmd":"npm install pino-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add pino-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add pino-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used as a transport for Pino logger; required for programmatic usage.","package":"pino","optional":false},{"reason":"MongoDB Node.js driver for database operations.","package":"mongodb","optional":false}],"imports":[{"note":"ESM import, but CommonJS require works in Node < 16. Package is ESM-only from v3? (check)","wrong":"const pino = require('pino')","symbol":"pino","correct":"import pino from 'pino'"},{"note":"For modern Pino transport, use pino.transport. Legacy require pattern is still supported but deprecated.","wrong":"const transport = require('pino-mongodb')({...})","symbol":"transport","correct":"import { pino } from 'pino';\nconst transport = pino.transport({ target: 'pino-mongodb', options: {...} })"},{"note":"CLI usage reads from stdin; does not require Node code.","wrong":"pino-mongodb --help","symbol":"pino-mongodb CLI","correct":"echo '{\"msg\":\"hello\"}' | npx pino-mongodb --collection logs mongodb://localhost:27017/mydb"}],"quickstart":{"code":"import pino from 'pino';\nconst transport = pino.transport({\n  target: 'pino-mongodb',\n  level: 'info',\n  options: {\n    uri: process.env.MONGO_URI ?? 'mongodb://localhost:27017/',\n    database: 'logs',\n    collection: 'app-logs',\n    mongoOptions: {\n      auth: {\n        username: process.env.MONGO_USER ?? '',\n        password: process.env.MONGO_PASS ?? ''\n      }\n    }\n  }\n});\nconst logger = pino(transport);\nlogger.info({ user: 'Alice', action: 'login' }, 'User logged in');\n\n// For CLI usage:\n// echo '{\"msg\":\"hello\"}' | pino-mongodb --collection logs mongodb://localhost:27017/mydb","lang":"typescript","description":"Sets up Pino logger with MongoDB transport and logs a sample message. Also shows alternative CLI usage."},"warnings":[{"fix":"Use parseLine option to transform log objects: opts.parseLine = (str) => { const obj = JSON.parse(str); // wrap problematic keys }","message":"MongoDB does not accept keys starting with '$' (e.g., $and). Log objects containing such keys will fail to insert. Wrap them under a property like 'query'.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use pino.transport({ target: 'pino-mongodb', options: { ... } })","message":"Legacy transport interface (using require('pino-mongodb') directly) is deprecated in favor of pino.transport.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Avoid using reserved keys or use parseLine to rename them.","message":"Missing logs: if the log object contains properties that conflict with MongoDB reserved fields (e.g., _id), they may be overwritten or cause errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2024':20 '5.0.0':17 'activ':81 'allow':41 'authent':57 'cli':38 'collect':50 'compar':58 'current':13 'custom':54 'direct':47 'ecosystem':29 'frequent':84 'handl':73 'high':75 'high-throughput':74 'insert':7 'integr':65 'javascript':86 'json':9 'legaci':37 'librari':79 'log':10,45,62,77,93 'logger':28,94 'maintain':82 'modern':33 'mongo':88 'mongodb':3,12,49,61,89,92 'option':52 'packag':22 'pars':55 'part':24 'pino':2,4,27,34,68,87,91 'pino-mongodb':1,90 'pipe':44 'pipelin':70 'releas':18,85 'seamless':66 'stabl':14 'stream':46 'structur':8 'support':31 'throughput':76 'transport':5,35,63 'usag':39 'user':42 'version':15","created_at":"2026-06-05T17:00:41.569225+00:00","updated_at":"2026-06-05T17:00:41.569225+00:00","problems":[{"fix":"Wrap such keys under a nested property, e.g., { query: { $and: [...] } }. Use parseLine option to transform logs.","cause":"Log object has a key starting with '$' which is not allowed by MongoDB.","error":"MongoServerError: Document contains invalid key: $and"},{"fix":"Upgrade to pino@7 or later, or use legacy require pattern.","cause":"Using older version of Pino (<7) that does not support pino.transport.","error":"TypeError: pino.transport is not a function"},{"fix":"Install the package: npm install pino-mongodb. If using ESM, use import syntax.","cause":"Package not installed or CommonJS require used when package is ESM-only.","error":"Error: Cannot find module 'pino-mongodb'"}],"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/pinojs/pino-mongodb","github":"https://github.com/pinojs/pino-mongodb","docs":null,"changelog":null,"pypi":null,"npm":"pino-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage","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}}