# lessware-mongo

> mongo middlware for lessware framework

Latest version **0.1.3** (published 2020-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install lessware-mongo
pnpm add lessware-mongo
yarn add lessware-mongo
bun add lessware-mongo
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2020-02-23 |
| First published | 2020-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | john k. grant |
| Maintainers | cyrfer |
| Keywords | mongodb, serverless, lessware, middlware, database |

## Links

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

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

- 0.1.3 (latest) — 2020-02-23
- 0.1.2 — 2020-01-27
- 0.1.1 — 2020-01-26
- 0.1.0 — 2020-01-26

## README

# lessware-mongo
mongo middleware for the lessware framework

## Install
`npm i -S lessware-mongo`

## API
`connect` a function that returns the middleware function.
- input parameter: a configuration object, whose keys are functions that must synchronously return configuration properties
  - `uri`: a function whose input is the `context` passed to the middleware, and the output is the mongodb connection string, e.g. `mongodb://localhost:27017`
  - `options`: a function whose input is the `context` object passed to the middleware, and the output is the options object passed to `MongoClient.connect(uri, options)`
- output: the middleware function for lessware's `framework` usage.

## Example Usage
An API Controller using `connect` middleware.

```javascript
// -- findTodo.js --
const { framework } = require('lessware')
const { connect } = require('lessware-mongo')

module.exports = framework([

  // attach mongo url from some async process, e.g. fetch from secret store
  async context => ({...context, mongoUrl: 'mongodb://localhost:27017'}),

  // attach `context.mongo.client`
  connect({
    uri: context => context.mongoUrl,
    options: context => context.config.mongo.options,
  }),

  // use `context.mongo.client`
  async context => {
    const result = await context.mongo.client
      .db('test')
      .collection('todo')
      .findOne({id: context.event.payload.id})

    return {
      statusCode: 200,
      body: JSON.stringify(result)
    }
  }
])

// -- index.js --
const findTodo = require('./findTodo')
const router = {findTodo}

// persist connections setup by middleware
const mongo = {}

exports.handler = async (event, ctx) => {
  return controller = router[event.fieldName]

  // pass the context object to the framework
  return controller({event, ctx})
}
```

# Maintainers

When buidling releases,
1. `npm test`
2. `git checkout -b feature-branch`
3. `git commit -m "your message"`
4. bump version 
   1. `npm version patch`
   2. `npm version minor`
5. `git push -u origin feature-branch`
6. submit merge request
7. maintainer merge, then `npm publish`

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