Skip to content

Instantly share code, notes, and snippets.

@astur astur/db.js
Created Feb 27, 2018

Embed
What would you like to do?
mongo 2/3 compatible db activation
const mongo = require('mongodb').MongoClient;
const mongoString = process.env.MONGO_URI ||
'mongodb://localhost:27017/test';
module.exports = mongo.connect(mongoString)
.then(client => {
if('databaseName' in client){
return client;
}
const db = client.db(mongoString.split('/').pop());
db.close = client.close.bind(client);
return db;
})
.catch(e => {
console.log(e.message);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.