Socket
Socket
Sign inDemoInstall

mongodb-uri

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongodb-uri

A parser and formatter for MongoDB URIs.


Version published
Maintainers
1
Install size
9.98 kB
Created

Readme

Source

mongodb-uri

Parse and format MongoDB URIs of the form:

mongodb://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database][?options]

Note that there are two minor differences between this format and the standard MongoDB connect string URI format:

  1. password is optional even when a username is supplied
  2. The slash before the database is not required when leaving out the database but specifying options

Neither of these differences should prevent this library from parsing any URI conforming to the standard format.

Usage

parse

var mongodbUri = require('mongodb-uri');
var uriObject = mongodbUri.parse('mongodb://user%3An%40me:p%40ssword@host:1234/d%40tabase?authenticationDatabase=%40dmin');
console.log(JSON.stringify(uriObject, null, 4));
{
    "scheme": "mongodb",
    "hosts": [
        {
            "host": "host",
            "port": 1234
        }
    ],
    "username": "user:n@me",
    "password": "p@ssword",
    "options": {
        "authenticationDatabase": "@dmin"
    },
    "database": "d@tabase"
}

format

var mongodbUri = require('mongodb-uri');
var uri = mongodbUri.format(
        {
            username: 'user:n@me',
            password: 'p@ssword',
            hosts: [
                {
                    host: 'host',
                    port: 1234
                }
            ],
            database: 'd@tabase',
            options: {
                authenticationDatabase: '@dmin'
            }
        }
);
console.log(uri);
mongodb://user%3An%40me:p%40ssword@host:1234/d%40tabase?authenticationDatabase=%40dmin

Keywords

FAQs

Last updated on 04 Jun 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc