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 = 'mongodb://localhost:27017/connect-test'; const coll = db;coll;
is equivalent to:
const mongo = ; ;
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"}]})'