Skip to content

Commit

Permalink
fix(database): removed incorrect events
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Oct 1, 2018
1 parent 0156c4b commit 357752d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@ module.exports.init = function(callback, connectionString, opts) {
if (opts) options = opts;
if (!_.isUndefined(process.env.MONGOHQ_URL)) CONNECTION_URI = process.env.MONGOHQ_URL.trim();

mongoose.connection.once('error', function(e) {
winston.error('Oh no, something went wrong with DB! - ' + e.message);
db.connection = null;
return callback(e, null);
});
if (db.connection)
return callback(null, db);

mongoose.connection.once('connected', function() {
mongoose.Promise = global.Promise;
mongoose.connect(CONNECTION_URI, options).then(function() {
if (!process.env.FORK)
winston.info('Connected to MongoDB');

db.connection = mongoose.connection;
return callback(null, db);
});

if (db.connection)
return callback(null, db);
}).catch(function(e) {
winston.error('Oh no, something went wrong with DB! - ' + e.message);
db.connection = null;

mongoose.Promise = global.Promise;
mongoose.connect(CONNECTION_URI, options).catch(function(e) { return callback(e, null); });
return callback(e, null);
});
};

module.exports.db = db;

0 comments on commit 357752d

Please sign in to comment.