# mongodb-connection-model

> MongoDB connection model

Latest version **22.4.1** (published 2023-06-06) · SSPL license · 0 weekly downloads

## Install

```sh
npm install mongodb-connection-model
pnpm add mongodb-connection-model
yarn add mongodb-connection-model
bun add mongodb-connection-model
```

## 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 | 22.4.1 |
| Published | 2023-06-06 |
| First published | 2015-09-09 |
| Weekly downloads | 0 |
| License | SSPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 82.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lucas Hrabovsky |
| Maintainers | mongo-j, mabaasit, alexander_schroll, chuck.kalmanek, mongodb-js-user, rueckstiess, durran, lerouxb, fredtruman, mbroadst, hswolff, satyasinha, matt_d_rat, rhysm, tomhollander, alena.khineika, jeff-allen-mongo, mmarcon, jonathan.balsano, mongodb-build, jack.weir, stennie, mcasimir, kristina.stefano, jarjee, shaketbaby, devtoolsbot, addaleax, gribnoysup, mutukrish, wz3chen, imlucas, kangas, judahschvimer |
| Keywords | mongodb-js |

## Links

- npm: https://www.npmjs.com/package/mongodb-connection-model
- Repository: https://github.com/mongodb-js/compass
- Issues: https://jira.mongodb.org/projects/COMPASS/issues
- npm.io page: https://npm.io/package/mongodb-connection-model

## Dependencies (10)

- [raf](https://npm.io/package/raf.md) ^3.4.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [mongodb3](https://npm.io/package/mongodb3.md) npm:mongodb@^3.6.3
- [os-dns-native](https://npm.io/package/os-dns-native.md) ^1.2.0
- [storage-mixin](https://npm.io/package/storage-mixin.md) ^5.1.5
- [ampersand-model](https://npm.io/package/ampersand-model.md) ^8.0.1
- [resolve-mongodb-srv](https://npm.io/package/resolve-mongodb-srv.md) ^1.1.2
- [@mongodb-js/compass-utils](https://npm.io/package/@mongodb-js/compass-utils.md) ^0.3.1
- [ampersand-rest-collection](https://npm.io/package/ampersand-rest-collection.md) ^6.0.0
- [mongodb-connection-string-url](https://npm.io/package/mongodb-connection-string-url.md) ^2.6.0

## 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

- 22.4.1 (latest) — 2023-06-06
- 0.0.0-next-5bb899576d8b95cb24b170e4fb80a7a4cc89beac (next) — 2023-07-24
- 0.0.0-experimental-1c53312ce4905234885618d41ae95fde9c21aa18 (experimental) — 2022-09-26
- 0.0.0-next-1d0257ec5ae772888fbfb677bbacf8cd7dfb3127 — 2023-07-21
- 0.0.0-next-8c579fa95e9deb46d73653d702f7f3b0e41efeb8 — 2023-07-21
- 0.0.0-next-247cba5e738b47e2c433fd1bc2e3d0ed48142ca5 — 2023-07-13
- 0.0.0-next-a7eb730693b63501028444f9ef6b634620af6e37 — 2023-07-03
- 0.0.0-next-835937ee6a94b541fd12d3d0c54d829fb2d0e492 — 2023-06-30
- 0.0.0-next-c584ad92337ea0098e7068e83ed68dd13565b7da — 2023-06-30
- 0.0.0-next-99faf39dcaa3321ec39c2a4a4c7b67e04f3c753e — 2023-06-28
- 0.0.0-next-f0a5a0fe0d39e23cbafd19676a6f8bc00f4480b5 — 2023-06-24
- 0.0.0-next-3ddf2b32a13c98a8713916c7c20185f8ae9a9327 — 2023-06-24
- 0.0.0-next-a6a1fbc898ffbe115f44ef184f30cf0d9348f9c2 — 2023-06-14
- 0.0.0-next-58b07e3b9faef89f8f737552ca57d6db6e0ea503 — 2023-06-14
- 0.0.0-next-80a9e175edd3eabee53daee876d77943872e4205 — 2023-06-12
- … 314 more at https://npm.io/package/mongodb-connection-model/versions

## README

# mongodb-connection-model  [![][npm_img]][npm_url]

*Not recommended for use. This package will be be updated or removed in COMPASS-5490*

## Usage

### Building URI

```javascript
const Connection = require('mongodb-connection-model');
const c = new Connection({ appname: 'My App Name' });

console.log(c.driverUrl)
>>> 'mongodb://localhost:27017/?readPreference=primary&appname=My%20App&ssl=false'
```

### Parsing URI

```javascript
const Connection = require('mongodb-connection-model');

Connection.from(
  'mongodb://someUsername:testPassword@localhost',
  (error, result) => {
    console.log(result);
    >>> `{
      hosts: [{ host: 'localhost', port: 27017 }],
      hostname: 'localhost',
      port: 27017,
      auth: {
        username: 'someUsername',
        password: 'testPassword',
        db: 'admin'
      },
      isSrvRecord: false,
      authStrategy: 'MONGODB',
      mongodbUsername: 'someUsername',
      mongodbPassword: 'testPassword',
      mongodbDatabaseName: 'admin',
      extraOptions: {},
      connectionType: 'NODE_DRIVER',
      readPreference: 'primary',
      kerberosCanonicalizeHostname: false,
      sslMethod: 'NONE',
      sshTunnel: 'NONE',
      sshTunnelPort: 22
    }`
  }
);
```

## Properties

MongoDB connection model is based on Ampersand.js framework and consist of [props](https://ampersandjs.com/docs/#ampersand-state-props) and [derived props](https://ampersandjs.com/docs/#ampersand-state-derived). The props object describes the observable properties that MongoDB connection model gets from the Node.js Driver API.

```javascript
const с = new Connection();
const props = с.getAttributes({ props: true });
```
## Derived Properties

Derived properties (also known as computed properties) are properties of the state object that depend on other properties to determine their value.

```javascript
const c = new Connection();
const derivedProps = c.getAttributes({ derived: true });
```

[npm_img]: https://img.shields.io/npm/v/mongodb-connection-model.svg?style=flat-square
[npm_url]: https://www.npmjs.org/package/mongodb-connection-model

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