Skip to content
Permalink
Browse files

fix(backup): mongodb binaries for mongodb 4 windows #138

chore(database): added support for MongoDB Atlas (shards)
  • Loading branch information...
polonel committed Apr 11, 2019
1 parent 2286538 commit 052d6da4714a25fa0e3673c4d55f026e2e461810
Showing with 46 additions and 19 deletions.
  1. +1 −1 src/backup/backup.js
  2. +6 −1 src/controllers/install.js
  3. +34 −16 src/database/index.js
  4. +5 −1 src/settings/defaults.js
@@ -126,7 +126,7 @@ function runBackup (callback) {
})
})
} else {
callback(new Error('MongoDump falied with code ' + code))
callback(new Error('MongoDump failed with code ' + code))
}
})
}
@@ -39,6 +39,9 @@ installController.mongotest = function (req, res) {
var CONNECTION_URI =
'mongodb://' + data.username + ':' + dbPassword + '@' + data.host + ':' + data.port + '/' + data.database

if (data.port === '---')
CONNECTION_URI = 'mongodb+srv://' + data.username + ':' + dbPassword + '@' + data.host + '/' + data.database

var child = require('child_process').fork(path.join(__dirname, '../../src/install/mongotest'), {
env: { FORK: 1, NODE_ENV: global.env, MONGOTESTURI: CONNECTION_URI }
})
@@ -124,6 +127,7 @@ installController.install = function (req, res) {

var dbPassword = encodeURIComponent(password)
var conuri = 'mongodb://' + username + ':' + dbPassword + '@' + host + ':' + port + '/' + database
if (port === '---') conuri = 'mongodb+srv://' + username + ':' + dbPassword + '@' + host + '/' + database

async.waterfall(
[
@@ -334,7 +338,8 @@ installController.install = function (req, res) {
port: port,
username: username,
password: password,
database: database
database: database,
shard: port === '---'
},
tokens: {
secret: chance.hash() + chance.md5(),
@@ -22,26 +22,40 @@ var mongoConnectionUri = {
port: process.env.TD_MONGODB_PORT || nconf.get('mongo:port') || '27017',
username: process.env.TD_MONGODB_USERNAME || nconf.get('mongo:username'),
password: process.env.TD_MONGODB_PASSWORD || nconf.get('mongo:password'),
database: process.env.TD_MONGODB_DATABASE || nconf.get('mongo:database')
database: process.env.TD_MONGODB_DATABASE || nconf.get('mongo:database'),
shard: process.env.TD_MONGODB_SHARD || nconf.get('mongo:shard')
}

var CONNECTION_URI = ''
if (!mongoConnectionUri.username)
if (!mongoConnectionUri.username) {
CONNECTION_URI =
'mongodb://' + mongoConnectionUri.server + ':' + mongoConnectionUri.port + '/' + mongoConnectionUri.database
else {
if (mongoConnectionUri.shard === true)
CONNECTION_URI = 'mongodb+srv://' + mongoConnectionUri.server + '/' + mongoConnectionUri.database
} else {
mongoConnectionUri.password = encodeURIComponent(mongoConnectionUri.password)
CONNECTION_URI =
'mongodb://' +
mongoConnectionUri.username +
':' +
mongoConnectionUri.password +
'@' +
mongoConnectionUri.server +
':' +
mongoConnectionUri.port +
'/' +
mongoConnectionUri.database
if (mongoConnectionUri.shard === true)
CONNECTION_URI =
'mongodb+srv://' +
mongoConnectionUri.username +
':' +
mongoConnectionUri.password +
'@' +
mongoConnectionUri.server +
'/' +
mongoConnectionUri.database
else
CONNECTION_URI =
'mongodb://' +
mongoConnectionUri.username +
':' +
mongoConnectionUri.password +
'@' +
mongoConnectionUri.server +
':' +
mongoConnectionUri.port +
'/' +
mongoConnectionUri.database
}

if (process.env.TD_MONGODB_URI) CONNECTION_URI = process.env.TD_MONGODB_URI
@@ -56,6 +70,7 @@ var options = {
module.exports.init = function (callback, connectionString, opts) {
if (connectionString) CONNECTION_URI = connectionString
if (opts) options = opts
options.dbName = mongoConnectionUri.database

if (db.connection) {
return callback(null, db)
@@ -71,8 +86,11 @@ module.exports.init = function (callback, connectionString, opts) {
}

db.connection = mongoose.connection

return callback(null, db)
mongoose.connection.db.admin().command({ buildInfo: 1 }, function (err, info) {
if (err) winston.warn(err.message)
db.version = info.version
return callback(null, db)
})
})
.catch(function (e) {
winston.error('Oh no, something went wrong with DB! - ' + e.message)
@@ -220,8 +220,12 @@ function createDirectories (callback) {
function downloadWin32MongoDBTools (callback) {
var http = require('http')
var os = require('os')
var semver = require('semver')
var dbVersion = require('../database').db.version || '3.6.9'
var fileVersion = semver(dbVersion).major + '.' + semver(dbVersion).minor

if (os.platform() === 'win32') {
var filename = 'mongodb-tools.3.6.9-win32x64.zip'
var filename = 'mongodb-tools.' + fileVersion + '-win32x64.zip'
var savePath = path.join(__dirname, '../backup/bin/win32/')
fs.ensureDirSync(savePath)
if (

0 comments on commit 052d6da

Please sign in to comment.
You can’t perform that action at this time.