Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/floatdrop/express-mongo-db

Get db connection in request object
https://github.com/floatdrop/express-mongo-db

Last synced: 3 months ago
JSON representation

Get db connection in request object

Awesome Lists containing this project

README

        

# express-mongo-db [![Build Status](https://travis-ci.org/floatdrop/express-mongo-db.svg?branch=master)](https://travis-ci.org/floatdrop/express-mongo-db)

> Get db connection in request

## Install

```
$ npm install --save express-mongo-db
```

## Usage

```js
var app = require('express')();

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

app.get('/', function (req, res, next) {
req.db // => Db object
});
```

## API

### expressMongoDb(uri, [options])

#### uri

*Required*
Type: `string`

[Connection string uri](http://docs.mongodb.org/manual/reference/connection-string/).

#### options

All options from [MongoClient](http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html) are accepted as well.

##### property

Type: `String`
Default: `db`

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

## License

MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)