1.0.1 • Published 3 years ago

mongo-uri-tool v1.0.1

Weekly downloads
6
License
ISC
Repository
github
Last release
3 years ago

mongo-uri

Build and parse MongoDB URIs easily.

Available Methods

NameRequired ParamsReturn Type
buildUriObject Connection host address and login credentialsString MongoDB Connection URI
parseUriString MongoDB Connection URIObject Connection host address and login credentials

buildUri

Params

NameData TypeRequiredDescriptionDefault
hostStringYesHost Address for the MongoDB Server
usernameStringYesLogin username
passwordStringYesLogin password
authdbStringYesAuthentication Source Database
srvBooleanNoIf true, the URI generated will have SRV enabled.false
dbStringNoThe database to which MongoDB has to connect"test"
portIntegerNoPort NumberIf not specified, the URI will be generated without port number.

parseUri

Params

NameData TypeRequiredDescriptionDefault
uriStringYesThe connection URI to parse

Examples

const mongoUri = require("mongo-uri");

let uri = mongoUri.buildUri({
    host: "cluster0.mongodb.net",
    username: "test",
    password: "password",
    authDb: "admin",
    srv: false,
    db: "mydb",
    port: 27017
});

console.log(uri);
// mongodb://test:password@cluster0.mongodb.net:27017/mydb?authSource=admin

let data = mongoUri.parseUri(uri);
console.log(data);
/*
{
    host: "cluster0.mongodb.net",
    username: "test",
    password: "password",
    authDb: "admin",
    srv: false,
    db: "mydb",
    port: 27017
}
*/