Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toymachiner62/mongo-factory
A very simple factory for managing mongo connection pooling
https://github.com/toymachiner62/mongo-factory
Last synced: 30 days ago
JSON representation
A very simple factory for managing mongo connection pooling
- Host: GitHub
- URL: https://github.com/toymachiner62/mongo-factory
- Owner: toymachiner62
- License: mit
- Created: 2014-08-30T04:31:07.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-29T20:12:14.000Z (almost 9 years ago)
- Last Synced: 2024-09-15T14:18:53.108Z (about 2 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 7
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#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 requestEnjoy!