2.3.0 • Published 5 years ago

mongo-lazy-connect v2.3.0

Weekly downloads
73
License
ISC
Repository
github
Last release
5 years ago

npm version build status coverage status

Similarly to other DBs (like const pool=new pg.Pool('pg://...'); pool.query('select ..').then(console.log)), let's allow a lazy access to the MongoDB driver pool

const db = require('mongo-lazy-connect')('mongodb://localhost:27017/connect-test');

const coll = db.collection('foo');
coll.insertOne({bar: 2}).then(() => {
	coll.find({}).limit(5).toArray().then(console.log);
});

is equivalent to:

const mongo = require('mongodb');

mongo('mongodb://localhost:27017')
	.then(client => {
		const coll = client.db('connect-test').collection('foo');
		coll.insertOne({bar: 2}).then(() => {
			coll.find({}).limit(5).toArray().then(console.log);
		});
	});

Note: for local testing, add a user on the DB

docker exec mongo-lazy-connect mongo admin --eval 'db.createUser({user: "mlc", pwd: "hunter2", roles: [{role: "root", db: "admin"}]})'
2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago