mongo-factory
Version:
A very simple mongo connection pool manager
44 lines (31 loc) • 1.36 kB
Markdown
[](https://travis-ci.org/toymachiner62/mongo-factory)
[](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.
```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);
});
```
The only parameter is a connection string for a MongoDB connection.
Exposes the MongoDB [ObjectID](http://mongodb.github.io/node-mongodb-native/2.0/tutorials/objectid/) function.
1. Clone project and run `npm install`
2. Add feature(s)
3. Add tests for it
4. Submit pull request
Enjoy!