From 8263f81d0c9f39b694fb628695401477bf81965e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 25 May 2018 11:56:40 -0400 Subject: [PATCH] fix pubsub when only mongodb is used --- src/database/mongo.js | 25 ++++++++++++++----------- src/database/mongo/pubsub.js | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index f16bd852a4..5b264253f5 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -62,7 +62,7 @@ mongoModule.questions = [ mongoModule.helpers = mongoModule.helpers || {}; mongoModule.helpers.mongo = require('./mongo/helpers'); -function getConnectionString() { +mongoModule.getConnectionString = function () { var usernamePassword = ''; if (nconf.get('mongo:username') && nconf.get('mongo:password')) { usernamePassword = nconf.get('mongo:username') + ':' + encodeURIComponent(nconf.get('mongo:password')) + '@'; @@ -90,15 +90,9 @@ function getConnectionString() { } return nconf.get('mongo:uri') || 'mongodb://' + usernamePassword + servers.join() + '/' + nconf.get('mongo:database'); -} - -mongoModule.init = function (callback) { - callback = callback || function () { }; - - var mongoClient = require('mongodb').MongoClient; - - var connString = getConnectionString(); +}; +mongoModule.getConnectionOptions = function () { var connOptions = { poolSize: 10, reconnectTries: 3600, @@ -106,7 +100,16 @@ mongoModule.init = function (callback) { autoReconnect: true, }; - connOptions = _.merge(connOptions, nconf.get('mongo:options') || {}); + return _.merge(connOptions, nconf.get('mongo:options') || {}); +}; + +mongoModule.init = function (callback) { + callback = callback || function () { }; + + var mongoClient = require('mongodb').MongoClient; + + var connString = mongoModule.getConnectionString(); + var connOptions = mongoModule.getConnectionOptions(); mongoClient.connect(connString, connOptions, function (err, _client) { if (err) { @@ -272,5 +275,5 @@ mongoModule.close = function (callback) { mongoModule.socketAdapter = function () { var mongoAdapter = require('socket.io-adapter-mongo'); - return mongoAdapter(getConnectionString()); + return mongoAdapter(mongoModule.getConnectionString()); }; diff --git a/src/database/mongo/pubsub.js b/src/database/mongo/pubsub.js index 83ff676294..7a4e7080d6 100644 --- a/src/database/mongo/pubsub.js +++ b/src/database/mongo/pubsub.js @@ -1,8 +1,8 @@ 'use strict'; -var mubsub = require('mubsub'); +var mubsub = require('mubsub-nbb'); var db = require('../mongo'); -var client = mubsub(db.client); +var client = mubsub(db.getConnectionString(), db.getConnectionOptions()); module.exports = client.channel('pubsub');