koa-mongo-db

Get db connection in context

Usage no npm install needed!

<script type="module">
  import koaMongoDb from 'https://cdn.skypack.dev/koa-mongo-db';
</script>

README

koa-mongo-db

Get db connection in context

Install

$ npm install --save koa-mongo-db

Usage

use version 1 for koa 1

var app = require('koa')();

var koaMongoDb = require('koa-mongo-db');
app.use(koaMongoDb('mongodb://localhost/test'));

app.get('/', function * (next) {
    this.db // => Db object
});

API

koaMongoDb(uri, [options])

uri

Required
Type: string

Connection string uri.

options

All options from MongoClient are accepted as well.

property

Type: String
Default: db

Property on request object in which db connection will be stored.

License

MIT

Thanks to floatdrop for the original express-mongo-db.