# mongoing

> cloud function computing mongodb middleware

Latest version **1.1.3** (published 2019-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoing
pnpm add mongoing
yarn add mongoing
bun add mongoing
```

## 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.1.3 |
| Published | 2019-10-03 |
| First published | 2019-09-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | orzv |
| Maintainers | orzv |
| Keywords | cloud, function, computing, middleware, api, mongodb, collection, serverless, async, auto |

## Links

- npm: https://www.npmjs.com/package/mongoing
- npm.io page: https://npm.io/package/mongoing

## Dependencies (1)

- [mongodb](https://npm.io/package/mongodb.md) ^3.3.2

## 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.1.3 (latest) — 2019-10-03
- 1.1.2 — 2019-10-03
- 1.1.0 — 2019-10-02
- 1.0.0 — 2019-09-25

## README

# Mongoing

适合用于云函数的`mongodb`中间件

- 连接数据库，提取`collection`
- 函数逻辑结束自动关闭数据库连接

## 使用方法

搭配`aliyun-function-compat`或`fcapi`使用

数据库连接地址从`mongoing`第二个参数获取，如果未指定这个参数，则从环境变量`MONGODB`获取，

如果环境变量未指定，则使用`mongodb://127.0.0.1:27017/mongoing`

连接成功后，会自动获取所有`collection`并转换成对象表附加到最后一个参数

如果需要使用未使用过的集合，并且连接地址不通过第二个参数设置，可以在第二个参数指定`collection`数组

或者在第三个参数指定

可以通过访问`__client`和`__db`获取客户端连接对象和DB对象

```javascript
const mongoing = require('mongoing')
const fcapi = require('fcapi')

exports.handler = fcapi(mongoing(async (event, context, {__client, __db, users}) => {
    // 客户端连接
    __client

    // db
    __db

    // collection
    users
}))

// 指定连接地址
mongoing(callback, url)

// 指定collection
mongoing(callback, ['users', 'posts'])

// 指定连接地址和数组
mongoing(callback, url, ['users'])
```

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