Skip to content

A very opinionated way to connect with the mongodb driver.

Notifications You must be signed in to change notification settings

lakshmi-auth0/mongo-getdb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

An opinionated way to connect with the mongodb driver.

Versions:

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

About

A very opinionated way to connect with the mongodb driver.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 93.7%
  • Shell 6.3%