Skip to content

Instantly share code, notes, and snippets.

@bsatrom
Created Mar 14, 2017
Embed
What would you like to do?
const Dotenv = require('dotenv')
const Winston = require('winston')
const Mongo = require('mongodb').MongoClient
var XervoHost
Dotenv.config()
const createURI = (port, user, password) => {
if (!user || !password) {
return `mongodb://localhost:${port}`
}
return `mongodb://${user}:${password}@localhost:${port}`
}
const xervoURI = `${createURI(process.env.MONGO_DB_PORT)}/Modulus`
Mongo.connect(xervoURI, (err, db) => {
if (err) Winston.error(err)
Winston.info('Connected to Internal Xervo DB')
XervoHost = db
})
const dbURI = createURI(process.env.MONGO_DB_PORT,
process.env.MONGO_HOST_ADMIN_USER,
process.env.MONGO_HOST_ADMIN_PASSWORD)
Mongo.connect(dbURI, (err, db) => {
if (err) Winston.error(err)
Winston.info('Connected to Customer DB host')
if (!XervoHost) {
Winston.error('Not connected to Xervo DB. Aborting')
db.close()
return
}
db.admin().listDatabases().then((result) => {
let dbs = result.databases
Winston.info(`retreived ${dbs.length} databases on host`)
dbs.map((db) => {
XervoHost.collection('Databases').findOne({ id: db.name }, (err, result) => {
if (err) Winston.error(err)
Winston.info(result)
})
}).catch((err) => {
Winston.error(err)
db.close()
if (XervoHost) XervoHost.close()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment