mg

mongo-getdb

A very opinionated way to connect with the mongodb driver.

Showing:

Popularity

Downloads/wk

184

GitHub Stars

12

Maintenance

Last Commit

2yrs ago

Contributors

8

Package

Dependencies

1

Size (min+gzip)

9.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Build Status

An opinionated way to connect with the mongodb driver.

Versions:

mongo-getdbmongodb
mongo-getdb@^4mongodb@^3
mongo-getdb@^3mongodb@^2

Installation

npm install mongo-getdb

Usage

var getDb = require('mongo-getdb');

getDb.init('mongo://localhost/mydb');

getDb(function (db) {
    db.collection('products')
      .find({})
      .toArray(function(er, prods) {

      });
});

getDb.init allows the same parameters than MongoClient.connect.

Why?

Because I keep doing the same thing over and over everytime I want to use mongodb from node and because this is what works for us most of the time.

This will "memoize" the result of MongoClient.connect, so you can use getDb anywhere.

Usage with multiples databases

var getDb = require('mongo-getdb');

getDb.init('db-one', 'mongodb://localhost/mydb');
getDb.init('db-two', 'mongodb://localhost/mydb2');

getDb('db-one', function (db) {
    db.collection('products')
      .find({})
      .toArray(function(er, prods) {

      });
});

License

MIT - 2013 - José F. Romaniello

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100