5.0.1 • Published 2 years ago

mongo-getdb v5.0.1

Weekly downloads
122
License
MIT
Repository
github
Last release
2 years ago

Build Status

An opinionated way to connect with the mongodb driver.

Versions:

mongo-getdbmongodb
mongo-getdb@^5mongodb@^4
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

5.0.1

2 years ago

5.0.0

2 years ago

4.2.0

4 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.0

8 years ago

2.1.0

8 years ago

2.0.0

9 years ago

1.4.0

9 years ago

1.3.0

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago