Skip to content

Instantly share code, notes, and snippets.

@bsatrom
Created March 14, 2017 21:51
Show Gist options
  • Save bsatrom/8f9a25d92db14b7952520dcac781534d to your computer and use it in GitHub Desktop.
Save bsatrom/8f9a25d92db14b7952520dcac781534d to your computer and use it in GitHub Desktop.
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