aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongo-factory/README.md
blob: 81433b59fe3692cb0066b4dc1342663ac111f2a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#mongo-factory
[![Build Status](https://travis-ci.org/toymachiner62/mongo-factory.svg?branch=master)](https://travis-ci.org/toymachiner62/mongo-factory)
[![Code Climate](https://codeclimate.com/github/toymachiner62/mongo-factory/badges/gpa.svg)](https://codeclimate.com/github/toymachiner62/mongo-factory)

> The purpose of this module is to manage mongo connection pools without creating a new connection pool in every file.
>
> You can require this module in as many files as you want and every time you call `mongoFactory.getConnection` it returns
> a connection if one exists for the connection string passed in, or it instantiates the connection pool and
> then returns a connection.

## Usage

```js
var mongoFactory = require('mongo-factory');

mongoFactory.getConnection('mongodb://localhost:27017')
  .then(function(db) {
    // Use mongo's "db" object as you normally would.
    db.collection.find()...
  })
  .catch(function(err) {
    console.error(err);
  });
```

## API

#### `getConnection(mongodbConnectionString)`

The only parameter is a connection string for a MongoDB connection.

#### `ObjectId`

Exposes the MongoDB [ObjectID](http://mongodb.github.io/node-mongodb-native/2.0/tutorials/objectid/) function.

## Contributing

1. Clone project and run `npm install`
2. Add feature(s)
3. Add tests for it
4. Submit pull request

Enjoy!