Skip to content

Instantly share code, notes, and snippets.

Created Feb 27, 2018
What would you like to do?
mongo 2/3 compatible db activation
const mongo = require('mongodb').MongoClient;
const mongoString = process.env.MONGO_URI ||
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 => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment