Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino-mongodb

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-mongodb - npm Package Compare versions

Comparing version 2.1.2 to 3.0.0

lib/pino-transport.js

2

lib/log.js

@@ -7,3 +7,3 @@ 'use strict'

try {
log = JSON.parse(data)
log = typeof data === 'string' ? JSON.parse(data) : data

@@ -10,0 +10,0 @@ if (log.time) {

{
"name": "pino-mongodb",
"version": "2.1.2",
"version": "3.0.0",
"description": "Insert JSON from stdin into MongoDB",

@@ -9,3 +9,4 @@ "files": [

"scripts": {
"test": "tap test",
"test": "tap test/*.js",
"test:end2end": "npm test && tap --no-check-coverage test/end-to-end/*.js",
"lint": "eslint .",

@@ -39,15 +40,17 @@ "lint:fix": "npm run lint -- --fix",

"carrier": "0.3",
"commander": "6.1",
"mongodb": "3.6",
"muri": "1.3"
"commander": "8.2",
"mongodb": "4.1",
"muri": "1.3",
"pino-abstract-transport": "^0.2.0"
},
"devDependencies": {
"eslint": "7.9",
"eslint-config-standard": "14.1",
"eslint-plugin-import": "2.22",
"eslint": "7.32",
"eslint-config-standard": "16.0",
"eslint-plugin-import": "2.24",
"eslint-plugin-node": "11.1",
"eslint-plugin-promise": "4.2",
"eslint-plugin-standard": "4.0",
"tap": "14.10"
"eslint-plugin-promise": "5.1",
"eslint-plugin-standard": "5.0",
"pino": "^7.0.0-rc.4",
"tap": "15.0"
}
}

@@ -11,43 +11,51 @@ #!/usr/bin/env node

const makeInsert = require('./lib/makeInsert')
const transport = require('./lib/pino-transport')
program
.version(pkg.version)
.description(pkg.description)
.arguments('[mongo-url]')
.option('-c, --collection <name>', 'database collection', 'logs')
.option('-o, --stdout', 'output inserted documents into stdout', false)
.option('-e, --errors', 'output insertion errors into stderr', false)
.option('-u, --unified', 'use mongodb unified topology', false)
.parse(process.argv)
module.exports = transport
const mongoUrl = (program.args[0] || 'mongodb://localhost:27017/logs')
if (require.main === module) {
// used as cli
cli()
}
function handleConnection (e, mClient) {
if (e) {
throw e
}
function cli () {
program
.version(pkg.version)
.description(pkg.description)
.arguments('[mongo-url]')
.option('-c, --collection <name>', 'database collection', transport.defaultOption.collection)
.option('-o, --stdout', 'output inserted documents into stdout', false)
.option('-e, --errors', 'output insertion errors into stderr', false)
.parse(process.argv)
const dbName = parseMongoUrl(mongoUrl).db
const mongoUrl = (program.args[0] || transport.defaultOption.uri)
const db = mClient.db(dbName)
const emitter = carrier.carry(process.stdin)
const collection = db.collection(program.collection)
const insert = makeInsert(program.errors, program.stdout)
function handleConnection (e, mClient) {
if (e) {
throw e
}
emitter.on('line', (line) => {
insert(collection, log(line))
})
const dbName = parseMongoUrl(mongoUrl).db
process.on('SIGINT', () => {
mClient.close(process.exit)
})
}
const db = mClient.db(dbName)
const emitter = carrier.carry(process.stdin)
const collection = db.collection(program.collection)
const insert = makeInsert(program.errors, program.stdout)
const options = { useNewUrlParser: true }
if (program.unified) { options.useUnifiedTopology = true }
emitter.on('line', (line) => {
insert(collection, log(line))
})
MongoClient.connect(
mongoUrl,
options,
handleConnection
)
process.on('SIGINT', () => {
mClient.close(process.exit)
})
}
const options = {}
MongoClient.connect(
mongoUrl,
options,
handleConnection
)
}
# pino-mongodb
[![npm version](https://img.shields.io/npm/v/pino-mongodb)](https://www.npmjs.com/package/pino-mongodb)
[![Build Status](https://img.shields.io/github/workflow/status/pinojs/pino-mongodb/CI)](https://github.com/pinojs/pino-mongodb/actions)
[![Known Vulnerabilities](https://snyk.io/test/github/pinojs/pino-mongodb/badge.svg)](https://snyk.io/test/github/pinojs/pino-mongodb)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
> Insert JSON from stdin into MongoDB

@@ -13,7 +15,45 @@

```bash
$ npm i -g pino-mongodb
$ npm i pino-mongodb
```
## Get started
## Usage as Pino Transport
You can use this module as a [pino transport](https://getpino.io/#/docs/transports?id=v7-transports) like so:
```js
const pino = require('pino')
const transport = pino.transport({
uri: 'mongodb://localhost:27017/',
database: 'logs',
collection: 'log-collection',
mongoOptions: {
auth: {
username: 'one',
password: 'two'
}
}
})
pino(transport)
```
The `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).
Note 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.
For example on MongoDB 4:
```js
// IT DOES NOT WORK:
log.info({ $and: [{ a: 1 }, { b: 2 }] }, 'my query is')
// IT WORKS:
log.info({ query: { $and: [{ a: 1 }, { b: 2 }]} }, 'my query is')
```
## Usage as Pino Legacy Transport
Pino supports a [legacy transport interface](https://getpino.io/#/docs/transports?id=legacy-transports)
that is still supported by this module.
### Get started
```bash

@@ -31,3 +71,3 @@ $ echo '{"name": "Viktor"}' | pino-mongodb [options] [mongo-url]

## Usage
### CLI Options

@@ -42,6 +82,6 @@ ```

-c, --collection <name> database collection (default: "logs")
-o, --stdout output inserted documents into stdout
-e, --errors output insertion errors into stderr
-u, --unified use mongodb unified topology
-h, --help output usage information
-o, --stdout output inserted documents into stdout (default:
false)
-e, --errors output insertion errors into stderr (default: false)
-h, --help display help for command
```

@@ -48,0 +88,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc