# mongo-uri-tool

> Build and parse MongoDB URIs easily.

Latest version **1.0.1** (published 2020-12-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongo-uri-tool
pnpm add mongo-uri-tool
yarn add mongo-uri-tool
bun add mongo-uri-tool
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-12-30 |
| First published | 2020-12-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Tanmay Vij |
| Maintainers | tanmayvij |
| Keywords | mongodb, mongo, mongo, uri, mongodb, uri, uri, parser, uri, builder |

## Links

- npm: https://www.npmjs.com/package/mongo-uri-tool
- Repository: https://github.com/tanmayvij/mongo-uri
- Homepage: https://github.com/tanmayvij/mongo-uri#readme
- Issues: https://github.com/tanmayvij/mongo-uri/issues
- npm.io page: https://npm.io/package/mongo-uri-tool

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-12-30
- 1.0.0 — 2020-12-30

## README

# mongo-uri
Build and parse MongoDB URIs easily.

# Available Methods
| Name | Required Params | Return Type
--- | --- | ---
| buildUri | `Object` Connection host address and login credentials | `String` MongoDB Connection URI
| parseUri | `String` MongoDB Connection URI | `Object` Connection host address and login credentials

# buildUri
#### Params

| Name | Data Type | Required | Description | Default
--- | --- | --- | --- | ---
| `host` | String | Yes | Host Address for the MongoDB Server |
| `username` | String | Yes | Login username |
| `password` | String | Yes | Login password |
| `authdb` | String | Yes | Authentication Source Database |
| `srv` | Boolean | No | If true, the URI generated will have SRV enabled. | `false`
| `db` | String | No | The database to which MongoDB has to connect | "test"
| `port` | Integer | No | Port Number | If not specified, the URI will be generated without port number.

# parseUri
#### Params
| Name | Data Type | Required | Description | Default
--- | --- | --- | --- | ---
uri | String | Yes | The connection URI to parse

# Examples
```javascript
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
}
*/
```

---
_Source: https://npm.io/package/mongo-uri-tool · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
