Skip to content

Commit

Permalink
add db options as json string
Browse files Browse the repository at this point in the history
  • Loading branch information
bejavu committed Aug 21, 2017
1 parent 63d1947 commit d5a1015
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
var port = settings.port
var database = settings.name
var uri = settings.uri
var options = settings.options
mongoose = mongooseInstance || require('mongoose')
mongoose.plugin(merge)
var DefaultSchema = mongoose.Schema
Expand All @@ -38,7 +39,14 @@ module.exports = {
throw new Error('Can\'t connect to Database')
}
uri = uri || mongoUri.formatMongoose({username: username, password: password, hosts: [{host: host, port: port}], database: database})
var options = {
if (options) {
try {
options = JSON.parse(options)
} catch (e) {
options = null
}
}
options = options || {
server: {
socketOptions: {
keepAlive: 1,
Expand All @@ -48,10 +56,11 @@ module.exports = {
replset: {
socketOptions: {
keepAlive: 1,
connectTimeoutMS: 30000
connectTimeoutMS: 3000
}
}
}
console.log('options', JSON.stringify(options))
// CONNECTION EVENTS
mongoose.connection.on('connected', function () {
console.log('Database connected to: ' + uri)
Expand Down
1 change: 1 addition & 0 deletions lib/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = function (settingsDir) {
properties_default.db.pass = process.env.DB_PASS || process.env.DBPASS || properties_default.db.pass
properties_default.db.dir = process.env.DB_DIR || process.env.DBDIR || properties_default.db.dir
properties_default.db.uri = process.env.DB_URI || process.env.DBURI || properties_default.db.uri
properties_default.db.options = process.env.DB_OPTIONS || process.env.DBOPTIONS || properties_default.db.options
}
if (properties_default.redis || process.env.REDIS_HOST) {
properties_default.redis = properties_default.redis || {}
Expand Down

0 comments on commit d5a1015

Please sign in to comment.