{"id":19155413,"url":"https://github.com/pinojs/pino-mongodb","last_synced_at":"2025-04-13T06:40:25.261Z","repository":{"id":13114448,"uuid":"71550602","full_name":"pinojs/pino-mongodb","owner":"pinojs","description":":evergreen_tree: Insert JSON from stdin into MongoDB","archived":false,"fork":false,"pushed_at":"2024-04-29T07:11:58.000Z","size":364,"stargazers_count":55,"open_issues_count":11,"forks_count":18,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-24T09:35:51.435Z","etag":null,"topics":["insert","logging","mongodb","nodejs","pino-logs","pino-mongodb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pinojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-21T09:23:49.000Z","updated_at":"2024-11-28T09:27:41.000Z","dependencies_parsed_at":"2023-12-18T08:28:24.117Z","dependency_job_id":"38eb8d01-e615-4412-84ed-d4f588617810","html_url":"https://github.com/pinojs/pino-mongodb","commit_stats":{"total_commits":209,"total_committers":15,"mean_commits":"13.933333333333334","dds":0.6028708133971292,"last_synced_commit":"3b2a7009ff46dec42f1100e6bcf76a5902c34b83"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fpino-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fpino-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fpino-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinojs%2Fpino-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinojs","download_url":"https://codeload.github.com/pinojs/pino-mongodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["insert","logging","mongodb","nodejs","pino-logs","pino-mongodb"],"created_at":"2024-11-09T08:30:02.412Z","updated_at":"2025-04-13T06:40:25.240Z","avatar_url":"https://github.com/pinojs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pino-mongodb\n[![npm version](https://img.shields.io/npm/v/pino-mongodb)](https://www.npmjs.com/package/pino-mongodb)\n[![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-mongodb/CI)](https://github.com/pinojs/pino-mongodb/actions)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\n\u003e Insert JSON from stdin into MongoDB\n\nThis project is part of the `pino` logger family, however you can use it to parse and insert any\n`JSON` into the `mongo`.\n\n## Install\n\n```bash\n$ npm i pino-mongodb\n```\n\n## Usage as Pino Transport\n\nYou can use this module as a [pino transport](https://getpino.io/#/docs/transports?id=v7-transports) like so:\n\n```js\nconst pino = require('pino')\nconst transport = pino.transport({\n  target: 'pino-mongodb',\n  level: 'info',\n  options: {\n    uri: 'mongodb://localhost:27017/',\n    database: 'logs',\n    collection: 'log-collection',\n    mongoOptions: {\n      auth: {\n        username: 'one',\n        password: 'two'\n      }\n    }\n  }\n})\n\npino(transport)\n```\n\nThe `mongoOptions` is provided to the the standard mongodb client. All the available options are described on [its official documentation](https://mongodb.github.io/node-mongodb-native/4.1/interfaces/MongoClientOptions.html).\n\nNote that you may encouter missing logs in special cases: it dependes on data and mongo's version. Please checkout the [mongodb limitation](https://docs.mongodb.com/manual/reference/limits/) official documentation.  \nFor example on MongoDB 4:\n\n```js\n// IT DOES NOT WORK:\nlog.info({ $and: [{ a: 1 }, { b: 2 }] }, 'my query is')\n\n// IT WORKS:\nlog.info({ query: { $and: [{ a: 1 }, { b: 2 }]} }, 'my query is')\n```\n\nIf you want a custom parser to handle the above case. You need to wrap `pino-mongo` and pass a function through `option.parseLine`. Any value that is not a function will be ignored in this option.\n\n```js\n// mongo-transport.js\n'use strict'\n\nconst transport = require('pino-mongodb')\n\nmodule.exports = function(opts) {\n  opts.parseLine = function(str) { // `str` is passed from `pino` and expected to be a string\n    const obj = JSON.parse(str)\n    \n    // do anything you want...\n\n    return obj // return value is expected to be a json that will pass and save inside mongodb\n  }\n  return transport(opts)\n}\n\n// main.js\nconst pino = require('pino')\nconst transport = pino.transport({\n  target: './mongo-transport.js',\n  uri: 'mongodb://localhost:27017/logs',\n  collection: 'log-collection',\n})\npino(transport)\n```\n\n## Usage as Pino Legacy Transport\n\nPino supports a [legacy transport interface](https://getpino.io/#/docs/transports?id=legacy-transports)\nthat is still supported by this module.\n\n### Get started\n\n```bash\n$ echo '{\"name\": \"Viktor\"}' | pino-mongodb [options] [mongo-url]\n```\n\n```bash\n$ cat many.logs | pino-mongodb [options] [mongo-url]\n```\n\n```bash\n$ node ./app.js | pino-mongodb [options] [mongo-url]\n```\n\n### CLI Options\n\n```\nUsage: pino-mongodb [options] [mongo-url]\n\nInsert JSON from stdin into MongoDB\n\nOptions:\n  -V, --version            output the version number\n  -c, --collection \u003cname\u003e  database collection (default: \"logs\")\n  -o, --stdout             output inserted documents into stdout (default:\n                           false)\n  -e, --errors             output insertion errors into stderr (default: false)\n  -h, --help               display help for command\n```\n\n## Tests\n\nTo run unit tests:\n\n```bash\n$ npm t\n```\n\nTo run integrational tests with real mongo server:\n\n```bash\n$ npm run trial\n```\n\nNote, you will have to have `docker` and `docker-compose` installed\non your machine for that!\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinojs%2Fpino-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinojs%2Fpino-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinojs%2Fpino-mongodb/lists"}